#23: UOW Action filter should be able to work without middleware too.

pull/112/head
Halil İbrahim Kalkan 8 years ago
parent 3839edbab9
commit 1117073201

@ -18,7 +18,7 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow
using (var uow = unitOfWorkManager.Reserve(AbpUowActionFilter.UnitOfWorkReservationName))
{
await _next(httpContext);
await uow.CompleteAsync();
await uow.CompleteAsync(httpContext.RequestAborted);
}
}
}

@ -18,8 +18,28 @@ namespace Volo.Abp.AspNetCore.Mvc.Uow
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
_unitOfWorkManager.BeginReserved(UnitOfWorkReservationName);
await next();
if (!context.ActionDescriptor.IsControllerAction())
{
await next();
return;
}
if (_unitOfWorkManager.TryBeginReserved(UnitOfWorkReservationName))
{
await next();
return;
}
//TODO: Check if disabled. Get and apply attributes to control UOW.
using (var uow = _unitOfWorkManager.Begin())
{
var result = await next();
if (result.Exception == null || result.ExceptionHandled)
{
await uow.CompleteAsync(context.HttpContext.RequestAborted);
}
}
}
}
}

@ -10,7 +10,8 @@ namespace Volo.Abp.Uow
[NotNull]
IBasicUnitOfWork Begin([NotNull] UnitOfWorkStartOptions options);
[NotNull]
IBasicUnitOfWork BeginReserved([NotNull] string reservationName);
void BeginReserved([NotNull] string reservationName);
bool TryBeginReserved([NotNull] string reservationName);
}
}

@ -35,7 +35,15 @@ namespace Volo.Abp.Uow
return CreateUnitOfWork(options);
}
public IBasicUnitOfWork BeginReserved(string reservationName)
public void BeginReserved(string reservationName)
{
if (!TryBeginReserved(reservationName))
{
throw new AbpException($"Could not find a reserved unit of work with reservation name: {reservationName}");
}
}
public bool TryBeginReserved(string reservationName)
{
Check.NotNull(reservationName, nameof(reservationName));
@ -49,11 +57,11 @@ namespace Volo.Abp.Uow
if (uow == null)
{
throw new AbpException($"Could not find a reserved unit of work with reservation name: {reservationName}");
return false;
}
uow.IsReserved = false;
return uow;
return true;
}
private IUnitOfWork GetCurrentUnitOfWork()

@ -62,10 +62,9 @@ namespace Volo.Abp.Uow
_unitOfWorkManager.Current.ShouldBeNull();
var reserverUow = _unitOfWorkManager.BeginReserved("Reservation1");
_unitOfWorkManager.BeginReserved("Reservation1");
_unitOfWorkManager.Current.ShouldNotBeNull();
_unitOfWorkManager.Current.Id.ShouldBe(reserverUow.Id);
_unitOfWorkManager.Current.Id.ShouldBe(uow1.Id);
await uow1.CompleteAsync();

Loading…
Cancel
Save