Example #1
0
        protected virtual async Task WithUnitOfWorkAsync(RocketUnitOfWorkOptions 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();
                }
            }
        }
Example #2
0
        private RocketUnitOfWorkOptions CreateOptions(PageHandlerExecutingContext context, UnitOfWorkAttribute unitOfWorkAttribute)
        {
            var options = new RocketUnitOfWorkOptions();

            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);
        }
Example #3
0
        protected virtual async Task <TResult> WithUnitOfWorkAsync <TResult>(RocketUnitOfWorkOptions options, Func <Task <TResult> > func)
        {
            using (var scope = ServiceProvider.CreateScope())
            {
                var uowManager = scope.ServiceProvider.GetRequiredService <IUnitOfWorkManager>();

                using (var uow = uowManager.Begin(options))
                {
                    var result = await func();

                    await uow.CompleteAsync();

                    return(result);
                }
            }
        }