From 9abe03d24829d7b650612bf2f4d09a7fa8b95729 Mon Sep 17 00:00:00 2001 From: malik masis Date: Thu, 3 Nov 2022 09:57:35 +0300 Subject: [PATCH] Update DapperRepository.cs --- .../Repositories/Dapper/DapperRepository.cs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 911f213974c..3b2b14f9524 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 DapperRepository(IDbContextProvider dbContextProvider) 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); + } }