mirror of https://github.com/abpframework/abp
parent
c34deaac48
commit
0871e07326
@ -0,0 +1,39 @@
|
|||||||
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
|
namespace Volo.Abp.Uow;
|
||||||
|
|
||||||
|
[DisableConventionalRegistration]
|
||||||
|
public class AlwaysDisableTransactionsUnitOfWorkManager : IUnitOfWorkManager
|
||||||
|
{
|
||||||
|
private readonly UnitOfWorkManager _unitOfWorkManager;
|
||||||
|
|
||||||
|
public AlwaysDisableTransactionsUnitOfWorkManager(UnitOfWorkManager unitOfWorkManager)
|
||||||
|
{
|
||||||
|
_unitOfWorkManager = unitOfWorkManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IUnitOfWork Current => _unitOfWorkManager.Current;
|
||||||
|
|
||||||
|
public IUnitOfWork Begin(AbpUnitOfWorkOptions options, bool requiresNew = false)
|
||||||
|
{
|
||||||
|
options.IsTransactional = false;
|
||||||
|
return _unitOfWorkManager.Begin(options, requiresNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IUnitOfWork Reserve(string reservationName, bool requiresNew = false)
|
||||||
|
{
|
||||||
|
return _unitOfWorkManager.Reserve(reservationName, requiresNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BeginReserved(string reservationName, AbpUnitOfWorkOptions options)
|
||||||
|
{
|
||||||
|
options.IsTransactional = false;
|
||||||
|
_unitOfWorkManager.BeginReserved(reservationName, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryBeginReserved(string reservationName, AbpUnitOfWorkOptions options)
|
||||||
|
{
|
||||||
|
options.IsTransactional = false;
|
||||||
|
return _unitOfWorkManager.TryBeginReserved(reservationName, options);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
|
|
||||||
|
namespace Volo.Abp.Uow;
|
||||||
|
|
||||||
|
public static class UnitOfWorkCollectionExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddAlwaysDisableUnitOfWorkTransaction(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
return services.Replace(ServiceDescriptor.Singleton<IUnitOfWorkManager, AlwaysDisableTransactionsUnitOfWorkManager>());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Shouldly;
|
||||||
|
using Volo.Abp.Testing;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Volo.Abp.Uow;
|
||||||
|
|
||||||
|
public class AlwaysDisableUnitOfWorkTransaction_Tests: AbpIntegratedTest<AbpUnitOfWorkModule>
|
||||||
|
{
|
||||||
|
protected override void AfterAddApplication(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddAlwaysDisableUnitOfWorkTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void AlwaysDisableUnitOfWorkTransaction_Test()
|
||||||
|
{
|
||||||
|
GetService<UnitOfWorkManager>().ShouldNotBeNull();
|
||||||
|
|
||||||
|
var unitOfWorkManager = ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
|
||||||
|
unitOfWorkManager.GetType().ShouldBe(typeof(AlwaysDisableTransactionsUnitOfWorkManager));
|
||||||
|
|
||||||
|
using (var uow = unitOfWorkManager.Begin(isTransactional: true))
|
||||||
|
{
|
||||||
|
uow.Options.IsTransactional.ShouldBeFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue