Browse Source

Use LazyServiceProvider in MongoDbRepository & MemoryDbRepository

pull/6815/head
maliming 6 years ago
parent
commit
2e76df3de7
  1. 2
      framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs
  2. 14
      framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  3. 33
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

2
framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/RepositoryBase.cs

@ -6,9 +6,7 @@ using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Linq;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow; using Volo.Abp.Uow;

14
framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

@ -28,23 +28,19 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb
protected IMemoryDatabaseProvider<TMemoryDbContext> DatabaseProvider { get; } protected IMemoryDatabaseProvider<TMemoryDbContext> DatabaseProvider { get; }
public ILocalEventBus LocalEventBus { get; set; } public ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetService<ILocalEventBus>(NullLocalEventBus.Instance);
public IDistributedEventBus DistributedEventBus { get; set; } public IDistributedEventBus DistributedEventBus => LazyServiceProvider.LazyGetService<IDistributedEventBus>(NullDistributedEventBus.Instance);
public IEntityChangeEventHelper EntityChangeEventHelper { get; set; } public IEntityChangeEventHelper EntityChangeEventHelper => LazyServiceProvider.LazyGetService<IEntityChangeEventHelper>(NullEntityChangeEventHelper.Instance);
public IAuditPropertySetter AuditPropertySetter { get; set; } public IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetService<IGuidGenerator>(SimpleGuidGenerator.Instance);
public IGuidGenerator GuidGenerator { get; set; } public IAuditPropertySetter AuditPropertySetter => LazyServiceProvider.LazyGetRequiredService<IAuditPropertySetter>();
public MemoryDbRepository(IMemoryDatabaseProvider<TMemoryDbContext> databaseProvider) public MemoryDbRepository(IMemoryDatabaseProvider<TMemoryDbContext> databaseProvider)
{ {
DatabaseProvider = databaseProvider; DatabaseProvider = databaseProvider;
LocalEventBus = NullLocalEventBus.Instance;
DistributedEventBus = NullDistributedEventBus.Instance;
EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
} }
protected override IQueryable<TEntity> GetQueryable() protected override IQueryable<TEntity> GetQueryable()

33
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -37,29 +37,24 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
protected IMongoDbContextProvider<TMongoDbContext> DbContextProvider { get; } protected IMongoDbContextProvider<TMongoDbContext> DbContextProvider { get; }
public ILocalEventBus LocalEventBus { get; set; } public ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetService<ILocalEventBus>(NullLocalEventBus.Instance);
public IDistributedEventBus DistributedEventBus { get; set; } public IDistributedEventBus DistributedEventBus => LazyServiceProvider.LazyGetService<IDistributedEventBus>(NullDistributedEventBus.Instance);
public IEntityChangeEventHelper EntityChangeEventHelper { get; set; } public IEntityChangeEventHelper EntityChangeEventHelper => LazyServiceProvider.LazyGetService<IEntityChangeEventHelper>(NullEntityChangeEventHelper.Instance);
public IGuidGenerator GuidGenerator { get; set; } public IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetService<IGuidGenerator>(SimpleGuidGenerator.Instance);
public IAuditPropertySetter AuditPropertySetter { get; set; } public IAuditPropertySetter AuditPropertySetter => LazyServiceProvider.LazyGetRequiredService<IAuditPropertySetter>();
public IMongoDbBulkOperationProvider BulkOperationProvider { get; set; } public IMongoDbBulkOperationProvider BulkOperationProvider => LazyServiceProvider.LazyGetService<IMongoDbBulkOperationProvider>();
public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider) public MongoDbRepository(IMongoDbContextProvider<TMongoDbContext> dbContextProvider)
{ {
DbContextProvider = dbContextProvider; DbContextProvider = dbContextProvider;
LocalEventBus = NullLocalEventBus.Instance;
DistributedEventBus = NullDistributedEventBus.Instance;
EntityChangeEventHelper = NullEntityChangeEventHelper.Instance;
GuidGenerator = SimpleGuidGenerator.Instance;
} }
public async override Task<TEntity> InsertAsync( public override async Task<TEntity> InsertAsync(
TEntity entity, TEntity entity,
bool autoSave = false, bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -113,7 +108,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
} }
} }
public async override Task<TEntity> UpdateAsync( public override async Task<TEntity> UpdateAsync(
TEntity entity, TEntity entity,
bool autoSave = false, bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -216,7 +211,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
} }
} }
public async override Task DeleteAsync( public override async Task DeleteAsync(
TEntity entity, TEntity entity,
bool autoSave = false, bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -346,17 +341,17 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
} }
} }
public async override Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) public override async Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().ToListAsync(GetCancellationToken(cancellationToken)); return await GetMongoQueryable().ToListAsync(GetCancellationToken(cancellationToken));
} }
public async override Task<long> GetCountAsync(CancellationToken cancellationToken = default) public override async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{ {
return await GetMongoQueryable().LongCountAsync(GetCancellationToken(cancellationToken)); return await GetMongoQueryable().LongCountAsync(GetCancellationToken(cancellationToken));
} }
public async override Task<List<TEntity>> GetPagedListAsync( public override async Task<List<TEntity>> GetPagedListAsync(
int skipCount, int skipCount,
int maxResultCount, int maxResultCount,
string sorting, string sorting,
@ -370,7 +365,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public async override Task DeleteAsync( public override async Task DeleteAsync(
Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, bool>> predicate,
bool autoSave = false, bool autoSave = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
@ -390,7 +385,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
return GetMongoQueryable(); return GetMongoQueryable();
} }
public async override Task<TEntity> FindAsync( public override async Task<TEntity> FindAsync(
Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, bool>> predicate,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)

Loading…
Cancel
Save