Browse Source

Added autoSave to delete, added clock to some base classes.

pull/272/head
Halil İbrahim Kalkan 9 years ago
parent
commit
dfaad47bb1
  1. 3
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs
  2. 5
      src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs
  3. 3
      src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs
  4. 1
      src/Volo.Abp.Ddd.Domain/Volo.Abp.Ddd.Domain.csproj
  5. 5
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/AbpDddDomainModule.cs
  6. 16
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs
  7. 14
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs
  8. 4
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs
  9. 3
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Services/DomainService.cs
  10. 17
      src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
  11. 4
      src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

3
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpController.cs

@ -6,6 +6,7 @@ using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Volo.Abp.Session; using Volo.Abp.Session;
using Volo.Abp.Timing;
using Volo.Abp.Uow; using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.Mvc namespace Volo.Abp.AspNetCore.Mvc
@ -26,6 +27,8 @@ namespace Volo.Abp.AspNetCore.Mvc
protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current;
public IClock Clock { get; set; }
protected ILogger Logger => _lazyLogger.Value; protected ILogger Logger => _lazyLogger.Value;
private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true); private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true);
} }

5
src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs

@ -11,6 +11,7 @@ using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Volo.Abp.Session; using Volo.Abp.Session;
using Volo.Abp.Timing;
using Volo.Abp.Uow; using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.Mvc.RazorPages namespace Volo.Abp.AspNetCore.Mvc.RazorPages
@ -34,7 +35,9 @@ namespace Volo.Abp.AspNetCore.Mvc.RazorPages
public IAuthorizationService AuthorizationService { get; set; } public IAuthorizationService AuthorizationService { get; set; }
protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current;
public IClock Clock { get; set; }
protected ILogger Logger => _lazyLogger.Value; protected ILogger Logger => _lazyLogger.Value;
private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true); private Lazy<ILogger> _lazyLogger => new Lazy<ILogger>(() => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance, true);

3
src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs

@ -8,6 +8,7 @@ using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.ObjectMapping; using Volo.Abp.ObjectMapping;
using Volo.Abp.Session; using Volo.Abp.Session;
using Volo.Abp.Timing;
using Volo.Abp.Uow; using Volo.Abp.Uow;
namespace Volo.Abp.Application.Services namespace Volo.Abp.Application.Services
@ -33,6 +34,8 @@ namespace Volo.Abp.Application.Services
public ICurrentUser CurrentUser { get; set; } public ICurrentUser CurrentUser { get; set; }
public IClock Clock { get; set; }
public IAuthorizationService AuthorizationService { get; set; } public IAuthorizationService AuthorizationService { get; set; }
protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current;

1
src/Volo.Abp.Ddd.Domain/Volo.Abp.Ddd.Domain.csproj

@ -20,6 +20,7 @@
<ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" /> <ProjectReference Include="..\Volo.Abp.Guids\Volo.Abp.Guids.csproj" />
<ProjectReference Include="..\Volo.Abp.MultiTenancy.Abstractions\Volo.Abp.MultiTenancy.Abstractions.csproj" /> <ProjectReference Include="..\Volo.Abp.MultiTenancy.Abstractions\Volo.Abp.MultiTenancy.Abstractions.csproj" />
<ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" /> <ProjectReference Include="..\Volo.Abp.Threading\Volo.Abp.Threading.csproj" />
<ProjectReference Include="..\Volo.Abp.Timing\Volo.Abp.Timing.csproj" />
<ProjectReference Include="..\Volo.Abp.Uow\Volo.Abp.Uow.csproj" /> <ProjectReference Include="..\Volo.Abp.Uow\Volo.Abp.Uow.csproj" />
</ItemGroup> </ItemGroup>

5
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/AbpDddDomainModule.cs

@ -5,6 +5,7 @@ using Volo.Abp.Guids;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Abp.Timing;
using Volo.Abp.Uow; using Volo.Abp.Uow;
namespace Volo.Abp.Domain namespace Volo.Abp.Domain
@ -15,8 +16,8 @@ namespace Volo.Abp.Domain
typeof(AbpGuidsModule), typeof(AbpGuidsModule),
typeof(AbpMultiTenancyAbstractionsModule), typeof(AbpMultiTenancyAbstractionsModule),
typeof(AbpThreadingModule), typeof(AbpThreadingModule),
typeof(AbpUnitOfWorkModule) typeof(AbpTimingModule),
)] typeof(AbpUnitOfWorkModule))]
public class AbpDddDomainModule : AbpModule public class AbpDddDomainModule : AbpModule
{ {
public override void ConfigureServices(IServiceCollection services) public override void ConfigureServices(IServiceCollection services)

16
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IBasicRepository.cs

@ -14,7 +14,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="entity">Inserted entity</param> /// <param name="entity">Inserted entity</param>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save entity to database. /// Set true to automatically save entity to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
[NotNull] [NotNull]
TEntity Insert([NotNull] TEntity entity, bool autoSave = false); TEntity Insert([NotNull] TEntity entity, bool autoSave = false);
@ -24,7 +24,7 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param> /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="entity">Inserted entity</param> /// <param name="entity">Inserted entity</param>
@ -37,7 +37,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="entity">Entity</param> /// <param name="entity">Entity</param>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
[NotNull] [NotNull]
TEntity Update([NotNull] TEntity entity, bool autoSave = false); TEntity Update([NotNull] TEntity entity, bool autoSave = false);
@ -47,7 +47,7 @@ namespace Volo.Abp.Domain.Repositories
/// </summary> /// </summary>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param> /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="entity">Entity</param> /// <param name="entity">Entity</param>
@ -60,7 +60,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="entity">Entity to be deleted</param> /// <param name="entity">Entity to be deleted</param>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
void Delete([NotNull] TEntity entity, bool autoSave = false); //TODO: Return true if deleted void Delete([NotNull] TEntity entity, bool autoSave = false); //TODO: Return true if deleted
@ -70,7 +70,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="entity">Entity to be deleted</param> /// <param name="entity">Entity to be deleted</param>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param> /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
Task DeleteAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); //TODO: Return true if deleted Task DeleteAsync([NotNull] TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); //TODO: Return true if deleted
@ -120,7 +120,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="id">Primary key of the entity</param> /// <param name="id">Primary key of the entity</param>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
void Delete(TKey id, bool autoSave = false); //TODO: Return true if deleted void Delete(TKey id, bool autoSave = false); //TODO: Return true if deleted
@ -130,7 +130,7 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="id">Primary key of the entity</param> /// <param name="id">Primary key of the entity</param>
/// <param name="autoSave"> /// <param name="autoSave">
/// Set true to automatically save changes to database. /// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only saves changes with an explicit method call. /// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param> /// </param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param> /// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default); //TODO: Return true if deleted Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default); //TODO: Return true if deleted

14
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs

@ -28,7 +28,11 @@ namespace Volo.Abp.Domain.Repositories
/// given predicate. /// given predicate.
/// </summary> /// </summary>
/// <param name="predicate">A condition to filter entities</param> /// <param name="predicate">A condition to filter entities</param>
void Delete([NotNull] Expression<Func<TEntity, bool>> predicate); /// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
void Delete([NotNull] Expression<Func<TEntity, bool>> predicate, bool autoSave = false);
/// <summary> /// <summary>
/// Deletes many entities by function. /// Deletes many entities by function.
@ -36,9 +40,13 @@ namespace Volo.Abp.Domain.Repositories
/// This may cause major performance problems if there are too many entities with /// This may cause major performance problems if there are too many entities with
/// given predicate. /// given predicate.
/// </summary> /// </summary>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="predicate">A condition to filter entities</param> /// <param name="predicate">A condition to filter entities</param>
Task DeleteAsync([NotNull] Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default); /// <param name="autoSave">
/// Set true to automatically save changes to database.
/// This is useful for ORMs / database APIs those only save changes with an explicit method call, but you need to immediately save changes to the database.
/// </param>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
Task DeleteAsync([NotNull] Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default);
} }
public interface IRepository<TEntity, TKey> : IRepository<TEntity>, IBasicRepository<TEntity, TKey> public interface IRepository<TEntity, TKey> : IRepository<TEntity>, IBasicRepository<TEntity, TKey>

4
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs

@ -36,7 +36,7 @@ namespace Volo.Abp.Domain.Repositories
protected abstract IQueryable<TEntity> GetQueryable(); protected abstract IQueryable<TEntity> GetQueryable();
public virtual void Delete(Expression<Func<TEntity, bool>> predicate) public virtual void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{ {
foreach (var entity in GetQueryable().Where(predicate).ToList()) foreach (var entity in GetQueryable().Where(predicate).ToList())
{ {
@ -44,7 +44,7 @@ namespace Volo.Abp.Domain.Repositories
} }
} }
public virtual Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default) public virtual Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
Delete(predicate); Delete(predicate);
return Task.CompletedTask; return Task.CompletedTask;

3
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Services/DomainService.cs

@ -2,11 +2,14 @@ using System;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Timing;
namespace Volo.Abp.Domain.Services namespace Volo.Abp.Domain.Services
{ {
public abstract class DomainService : IDomainService public abstract class DomainService : IDomainService
{ {
public IClock Clock { get; set; }
public IGuidGenerator GuidGenerator { get; set; } public IGuidGenerator GuidGenerator { get; set; }
public ILoggerFactory LoggerFactory { get; set; } public ILoggerFactory LoggerFactory { get; set; }

17
src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs

@ -104,13 +104,28 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return DbSet.AsQueryable(); return DbSet.AsQueryable();
} }
public override async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default) public override void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{
base.Delete(predicate, autoSave);
if (autoSave)
{
DbContext.SaveChanges();
}
}
public override async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
var entities = await GetQueryable().Where(predicate).ToListAsync(GetCancellationToken(cancellationToken)); var entities = await GetQueryable().Where(predicate).ToListAsync(GetCancellationToken(cancellationToken));
foreach (var entity in entities) foreach (var entity in entities)
{ {
DbSet.Remove(entity); DbSet.Remove(entity);
} }
if (autoSave)
{
await DbContext.SaveChangesAsync(cancellationToken);
}
} }
public virtual async Task EnsureCollectionLoadedAsync<TProperty>( public virtual async Task EnsureCollectionLoadedAsync<TProperty>(

4
src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -60,12 +60,12 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
await Collection.DeleteOneAsync(CreateEntityFilter(entity), cancellationToken); await Collection.DeleteOneAsync(CreateEntityFilter(entity), cancellationToken);
} }
public override void Delete(Expression<Func<TEntity, bool>> predicate) public override void Delete(Expression<Func<TEntity, bool>> predicate, bool autoSave = false)
{ {
Collection.DeleteMany(Builders<TEntity>.Filter.Where(predicate)); Collection.DeleteMany(Builders<TEntity>.Filter.Where(predicate));
} }
public override async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default) public override async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await Collection.DeleteManyAsync(Builders<TEntity>.Filter.Where(predicate), cancellationToken); await Collection.DeleteManyAsync(Builders<TEntity>.Filter.Where(predicate), cancellationToken);
} }

Loading…
Cancel
Save