Browse Source

UnitOfWorkManager refactored.

pull/112/head
Halil İbrahim Kalkan 9 years ago
parent
commit
af0ccfc897
  1. 63
      src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManager.cs

63
src/Volo.Abp/Volo/Abp/Uow/UnitOfWorkManager.cs

@ -32,33 +32,7 @@ namespace Volo.Abp.Uow
options.RequiresNew = true; options.RequiresNew = true;
} }
var outerUow = _ambientUnitOfWork.UnitOfWork; return CreateUnitOfWork(options);
var scope = _serviceProvider.CreateScope();
IUnitOfWork unitOfWork;
try
{
unitOfWork = scope.ServiceProvider.GetRequiredService<IUnitOfWork>();
unitOfWork.SetOuter(outerUow);
unitOfWork.IsReserved = options.ReservationName != null;
unitOfWork.ReservationName = options.ReservationName;
}
catch
{
scope.Dispose();
throw;
}
_ambientUnitOfWork.SetUnitOfWork(unitOfWork);
unitOfWork.Disposed += (sender, args) =>
{
_ambientUnitOfWork.SetUnitOfWork(outerUow);
scope.Dispose();
};
return unitOfWork;
} }
public IBasicUnitOfWork BeginReserved(string reservationName) public IBasicUnitOfWork BeginReserved(string reservationName)
@ -66,7 +40,7 @@ namespace Volo.Abp.Uow
Check.NotNull(reservationName, nameof(reservationName)); Check.NotNull(reservationName, nameof(reservationName));
var uow = _ambientUnitOfWork.UnitOfWork; var uow = _ambientUnitOfWork.UnitOfWork;
//Find reserved unit of work starting from current and going to outers //Find reserved unit of work starting from current and going to outers
while (uow != null && !uow.IsReservedFor(reservationName)) while (uow != null && !uow.IsReservedFor(reservationName))
{ {
@ -85,7 +59,7 @@ namespace Volo.Abp.Uow
private IUnitOfWork GetCurrentUnitOfWork() private IUnitOfWork GetCurrentUnitOfWork()
{ {
var uow = _ambientUnitOfWork.UnitOfWork; var uow = _ambientUnitOfWork.UnitOfWork;
//Skip reserved unit of work //Skip reserved unit of work
while (uow != null && uow.IsReserved) while (uow != null && uow.IsReserved)
{ {
@ -94,5 +68,36 @@ namespace Volo.Abp.Uow
return uow; return uow;
} }
private IUnitOfWork CreateUnitOfWork(UnitOfWorkStartOptions options)
{
var scope = _serviceProvider.CreateScope();
try
{
var outerUow = _ambientUnitOfWork.UnitOfWork;
var unitOfWork = scope.ServiceProvider.GetRequiredService<IUnitOfWork>();
unitOfWork.SetOuter(outerUow);
unitOfWork.IsReserved = options.ReservationName != null;
unitOfWork.ReservationName = options.ReservationName;
_ambientUnitOfWork.SetUnitOfWork(unitOfWork);
unitOfWork.Disposed += (sender, args) =>
{
_ambientUnitOfWork.SetUnitOfWork(outerUow);
scope.Dispose();
};
return unitOfWork;
}
catch
{
scope.Dispose();
throw;
}
}
} }
} }
Loading…
Cancel
Save