|
|
|
@ -2,15 +2,18 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.Domain.Entities; |
|
|
|
using Volo.Abp.Linq; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
|
|
namespace Volo.Abp.Domain.Repositories |
|
|
|
{ |
|
|
|
public abstract class BasicRepositoryBase<TEntity> : |
|
|
|
IBasicRepository<TEntity>, |
|
|
|
public abstract class BasicRepositoryBase<TEntity> : |
|
|
|
IBasicRepository<TEntity>, |
|
|
|
IServiceProviderAccessor, |
|
|
|
IUnitOfWorkEnabled, |
|
|
|
ITransientDependency |
|
|
|
@ -18,6 +21,14 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
{ |
|
|
|
public IServiceProvider ServiceProvider { get; set; } |
|
|
|
|
|
|
|
public IDataFilter DataFilter { get; set; } |
|
|
|
|
|
|
|
public ICurrentTenant CurrentTenant { get; set; } |
|
|
|
|
|
|
|
public IAsyncQueryableExecuter AsyncExecuter { get; set; } |
|
|
|
|
|
|
|
public IUnitOfWorkManager UnitOfWorkManager { get; set; } |
|
|
|
|
|
|
|
public ICancellationTokenProvider CancellationTokenProvider { get; set; } |
|
|
|
|
|
|
|
protected BasicRepositoryBase() |
|
|
|
@ -27,6 +38,29 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
|
|
|
|
public abstract Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
public virtual async Task InsertManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
foreach (var entity in entities) |
|
|
|
{ |
|
|
|
await InsertAsync(entity, cancellationToken: cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
if (autoSave) |
|
|
|
{ |
|
|
|
await SaveChangesAsync(cancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual Task SaveChangesAsync(CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
if (UnitOfWorkManager?.Current != null) |
|
|
|
{ |
|
|
|
return UnitOfWorkManager?.Current.SaveChangesAsync(cancellationToken); |
|
|
|
} |
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
public abstract Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
public abstract Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default); |
|
|
|
@ -59,7 +93,7 @@ namespace Volo.Abp.Domain.Repositories |
|
|
|
} |
|
|
|
|
|
|
|
public abstract Task<TEntity> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default); |
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
var entity = await FindAsync(id, cancellationToken: cancellationToken); |
|
|
|
|