protected virtual async Task WithUnitOfWorkAsync(AbpUnitOfWorkOptions options, Func <Task> action) { using (var scope = ServiceProvider.CreateScope()) { var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>(); using (var uow = uowManager.Begin(options)) { await action(); await uow.CompleteAsync(); } } }
protected virtual TResult WithUnitOfWork <TResult>(AbpUnitOfWorkOptions options, Func <TResult> func) { using (var scope = ServiceProvider.CreateScope()) { var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>(); using (var uow = uowManager.Begin(options)) { var result = func(); uow.Complete(); return(result); } } }
protected virtual void WithUnitOfWork(AbpUnitOfWorkOptions options, Action action) { using (var scope = ServiceProvider.CreateScope()) { var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>(); using (var uow = uowManager.Begin(options)) { action(); uow.Complete(); } } }
private AbpUnitOfWorkOptions CreateOptions(PageHandlerExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute) { var options = new AbpUnitOfWorkOptions(); unitOfWorkAttribute?.SetOptions(options); if (unitOfWorkAttribute?.IsTransactional == null) { options.IsTransactional = _defaultOptions.CalculateIsTransactional( autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase) ); } return(options); }
private AbpUnitOfWorkOptions CreateOptions(ActionExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute) { var options = new AbpUnitOfWorkOptions(); unitOfWorkAttribute?.SetOptions(options); if (unitOfWorkAttribute?.IsTransactional == null) { var abpUnitOfWorkDefaultOptions = context.GetRequiredService <IOptions <AbpUnitOfWorkDefaultOptions> >().Value; options.IsTransactional = abpUnitOfWorkDefaultOptions.CalculateIsTransactional( autoValue: !string.Equals(context.HttpContext.Request.Method, HttpMethod.Get.Method, StringComparison.OrdinalIgnoreCase) ); } return(options); }
protected virtual async Task <TResult> WithUnitOfWorkAsync <TResult>(AbpUnitOfWorkOptions options, Func <Task <TResult> > func) { using (IServiceScope scope = ServiceProvider.CreateScope()) { IUnitOfWorkManager uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>(); using (IUnitOfWork uow = uowManager.Begin(options)) { TResult result = await func(); await uow.CompleteAsync(); return(result); } } }
private AbpUnitOfWorkOptions CreateOptions(IServiceProvider serviceProvider, IAbpMethodInvocation invocation, [CanBeNull] UnitOfWorkAttribute unitOfWorkAttribute) { var options = new AbpUnitOfWorkOptions(); unitOfWorkAttribute?.SetOptions(options); if (unitOfWorkAttribute?.IsTransactional == null) { var defaultOptions = serviceProvider.GetRequiredService <IOptions <AbpUnitOfWorkDefaultOptions> >().Value; options.IsTransactional = defaultOptions.CalculateIsTransactional( autoValue: serviceProvider.GetRequiredService <IUnitOfWorkTransactionBehaviourProvider>().IsTransactional ?? !invocation.Method.Name.StartsWith("Get", StringComparison.InvariantCultureIgnoreCase) ); } return(options); }
//TODO: More constructors! public virtual void SetOptions(AbpUnitOfWorkOptions options) { if (IsTransactional.HasValue) { options.IsTransactional = IsTransactional.Value; } if (Timeout.HasValue) { options.Timeout = Timeout; } if (IsolationLevel.HasValue) { options.IsolationLevel = IsolationLevel; } }
public IUnitOfWork Begin(AbpUnitOfWorkOptions options, bool requiresNew = false) { Check.NotNull(options, nameof(options)); var currentUow = Current; if (currentUow != null && !requiresNew) { return(new ChildUnitOfWork(currentUow)); } var unitOfWork = CreateNewUnitOfWork(); unitOfWork.Initialize(options); return(unitOfWork); }
public bool TryBeginReserved(string reservationName, AbpUnitOfWorkOptions options) { Check.NotNull(reservationName, nameof(reservationName)); var uow = _ambientUnitOfWork.UnitOfWork; //Find reserved unit of work starting from current and going to outers while (uow != null && !uow.IsReservedFor(reservationName)) { uow = uow.Outer; } if (uow == null) { return(false); } uow.Initialize(options); return(true); }
public void Initialize(AbpUnitOfWorkOptions options) { _parent.Initialize(options); }