|
|
|
@ -17,26 +17,6 @@ namespace MyCompanyName.MyProjectName |
|
|
|
options.UseAutofac(); |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual void WithUnitOfWork(Action action) |
|
|
|
{ |
|
|
|
WithUnitOfWork(new AbpUnitOfWorkOptions(), action); |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual Task WithUnitOfWorkAsync(Func<Task> func) |
|
|
|
{ |
|
|
|
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); |
|
|
|
@ -57,26 +37,6 @@ namespace MyCompanyName.MyProjectName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual TResult WithUnitOfWork<TResult>(Func<TResult> func) |
|
|
|
{ |
|
|
|
return WithUnitOfWork(new AbpUnitOfWorkOptions(), func); |
|
|
|
} |
|
|
|
|
|
|
|
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 Task<TResult> WithUnitOfWorkAsync<TResult>(Func<Task<TResult>> func) |
|
|
|
{ |
|
|
|
return WithUnitOfWorkAsync(new AbpUnitOfWorkOptions(), func); |
|
|
|
|