|
|
|
@ -1,9 +1,14 @@ |
|
|
|
using System; |
|
|
|
using System.Data; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
|
using Volo.Abp.Data; |
|
|
|
using Volo.Abp.DependencyInjection; |
|
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
using Volo.Abp.MultiTenancy; |
|
|
|
using Volo.Abp.Threading; |
|
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
|
|
namespace Volo.Abp.Domain.Repositories.Dapper; |
|
|
|
@ -11,6 +16,16 @@ namespace Volo.Abp.Domain.Repositories.Dapper; |
|
|
|
public class DapperRepository<TDbContext> : IDapperRepository, IUnitOfWorkEnabled |
|
|
|
where TDbContext : IEfCoreDbContext |
|
|
|
{ |
|
|
|
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } |
|
|
|
|
|
|
|
public IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService<IDataFilter>(); |
|
|
|
|
|
|
|
public ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>(); |
|
|
|
|
|
|
|
public IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>(); |
|
|
|
|
|
|
|
public ICancellationTokenProvider CancellationTokenProvider => LazyServiceProvider.LazyGetService<ICancellationTokenProvider>(NullCancellationTokenProvider.Instance); |
|
|
|
|
|
|
|
private readonly IDbContextProvider<TDbContext> _dbContextProvider; |
|
|
|
|
|
|
|
public DapperRepository(IDbContextProvider<TDbContext> dbContextProvider) |
|
|
|
@ -27,4 +42,9 @@ public class DapperRepository<TDbContext> : IDapperRepository, IUnitOfWorkEnable |
|
|
|
public IDbTransaction DbTransaction => _dbContextProvider.GetDbContext().Database.CurrentTransaction?.GetDbTransaction(); |
|
|
|
|
|
|
|
public async Task<IDbTransaction> GetDbTransactionAsync() => (await _dbContextProvider.GetDbContextAsync()).Database.CurrentTransaction?.GetDbTransaction(); |
|
|
|
|
|
|
|
protected virtual CancellationToken GetCancellationToken(CancellationToken preferredValue = default) |
|
|
|
{ |
|
|
|
return CancellationTokenProvider.FallbackToProvider(preferredValue); |
|
|
|
} |
|
|
|
} |
|
|
|
|