mirror of https://github.com/abpframework/abp.git
12 changed files with 199 additions and 21 deletions
@ -0,0 +1,25 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.AspNetCore.Mvc.Filters; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Uow; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.Uow |
||||
|
{ |
||||
|
public class AbpUowActionFilter : IAsyncActionFilter, ITransientDependency |
||||
|
{ |
||||
|
public const string UnitOfWorkReservationName = "_AbpActionUnitOfWork"; |
||||
|
|
||||
|
private readonly IUnitOfWorkManager _unitOfWorkManager; |
||||
|
|
||||
|
public AbpUowActionFilter(IUnitOfWorkManager unitOfWorkManager) |
||||
|
{ |
||||
|
_unitOfWorkManager = unitOfWorkManager; |
||||
|
} |
||||
|
|
||||
|
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) |
||||
|
{ |
||||
|
_unitOfWorkManager.BeginReserved(UnitOfWorkReservationName); |
||||
|
await next(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,7 +1,15 @@ |
|||||
namespace Volo.Abp.Uow |
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Uow |
||||
{ |
{ |
||||
public interface IUnitOfWork : IBasicUnitOfWork, IDatabaseApiContainer |
public interface IUnitOfWork : IBasicUnitOfWork, IDatabaseApiContainer |
||||
{ |
{ |
||||
|
IUnitOfWork Outer { get; } |
||||
|
|
||||
|
bool IsReserved { get; set; } |
||||
|
|
||||
|
string ReservationName { get; set; } |
||||
|
|
||||
|
void SetOuter([CanBeNull] IUnitOfWork outer); |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,14 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Uow |
||||
|
{ |
||||
|
public static class UnitOfWorkExtensions |
||||
|
{ |
||||
|
public static bool IsReservedFor([NotNull] this IUnitOfWork unitOfWork, string reservationName) |
||||
|
{ |
||||
|
Check.NotNull(unitOfWork, nameof(unitOfWork)); |
||||
|
|
||||
|
return unitOfWork.IsReserved && unitOfWork.ReservationName == reservationName; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.Uow |
||||
|
{ |
||||
|
public static class UnitOfWorkManagerExtensions |
||||
|
{ |
||||
|
[NotNull] |
||||
|
public static IBasicUnitOfWork Begin([NotNull] this IUnitOfWorkManager unitOfWorkManager) |
||||
|
{ |
||||
|
Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager)); |
||||
|
|
||||
|
return unitOfWorkManager.Begin(new UnitOfWorkStartOptions()); |
||||
|
} |
||||
|
|
||||
|
[NotNull] |
||||
|
public static IBasicUnitOfWork BeginNew([NotNull] this IUnitOfWorkManager unitOfWorkManager) |
||||
|
{ |
||||
|
Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager)); |
||||
|
|
||||
|
return unitOfWorkManager.Begin(new UnitOfWorkStartOptions {RequiresNew = true}); |
||||
|
} |
||||
|
|
||||
|
[NotNull] |
||||
|
public static IBasicUnitOfWork Reserve([NotNull] this IUnitOfWorkManager unitOfWorkManager, [NotNull] string reservationName) |
||||
|
{ |
||||
|
Check.NotNull(unitOfWorkManager, nameof(unitOfWorkManager)); |
||||
|
Check.NotNull(reservationName, nameof(reservationName)); |
||||
|
|
||||
|
return unitOfWorkManager.Begin(new UnitOfWorkStartOptions { ReservationName = reservationName }); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue