diff --git a/framework/src/Volo.Abp.Dapper/Volo/Abp/Domain/Repositories/Dapper/DapperRepository.cs b/framework/src/Volo.Abp.Dapper/Volo/Abp/Domain/Repositories/Dapper/DapperRepository.cs index 911f213974..3b2b14f952 100644 --- a/framework/src/Volo.Abp.Dapper/Volo/Abp/Domain/Repositories/Dapper/DapperRepository.cs +++ b/framework/src/Volo.Abp.Dapper/Volo/Abp/Domain/Repositories/Dapper/DapperRepository.cs @@ -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 : IDapperRepository, IUnitOfWorkEnabled where TDbContext : IEfCoreDbContext { + public IAbpLazyServiceProvider LazyServiceProvider { get; set; } + + public IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService(); + + public ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService(); + + public IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService(); + + public ICancellationTokenProvider CancellationTokenProvider => LazyServiceProvider.LazyGetService(NullCancellationTokenProvider.Instance); + private readonly IDbContextProvider _dbContextProvider; public DapperRepository(IDbContextProvider dbContextProvider) @@ -27,4 +42,9 @@ public class DapperRepository : IDapperRepository, IUnitOfWorkEnable public IDbTransaction DbTransaction => _dbContextProvider.GetDbContext().Database.CurrentTransaction?.GetDbTransaction(); public async Task GetDbTransactionAsync() => (await _dbContextProvider.GetDbContextAsync()).Database.CurrentTransaction?.GetDbTransaction(); + + protected virtual CancellationToken GetCancellationToken(CancellationToken preferredValue = default) + { + return CancellationTokenProvider.FallbackToProvider(preferredValue); + } }