correct me please if I'm wrong, but out of the blue, I didn't find an acceptable way to run jobs inside a TransactionScope...
I mean, if you have a look at CoreBackgroundJobPerformer you will notice that there is no an extension point inside an opened ServiceScope.
However, normally I would start and commit a transaction inside a scope, roughly something like that...
public async object Perform(PerformContext context)
{
using (var scope = _activator.BeginScope(context))
{
//
// an extension point (like a new Job Filter type)
//
await ScopeHasBeenCreated(scope);
object instance = null;
if (context.BackgroundJob.Job == null)
{
throw new InvalidOperationException("Can't perform a background job with a null job.");
}
if (!context.BackgroundJob.Job.Method.IsStatic)
{
instance = scope.Resolve(context.BackgroundJob.Job.Type);
if (instance == null)
{
throw new InvalidOperationException(
$"JobActivator returned NULL instance of the '{context.BackgroundJob.Job.Type}' type.");
}
}
var arguments = SubstituteArguments(context);
var result = InvokeMethod(context, instance, arguments);
//
// an extension point (like a new Job Filter type)
//
await BeforeScopeDestroyed(scope);
return result;
}
}
async Task ScopeHasBeenCreated(IServiceScope scope)
{
await scope.ServiceProvider.GetServices<IUnitOfWork>().BeginTransaction();
}
async Task BeforeScopeDestroyed(IServiceScope scope)
{
await scope.ServiceProvider.GetServices<IUnitOfWork>().Commit();
}
Barely can we use existing job filters to start/stop a UoW, because we are not inside a DI scope of a job.
What do you think about it and do you see any problems to add two Job filters to handle this problem?
Hi everyone,
correct me please if I'm wrong, but out of the blue, I didn't find an acceptable way to run jobs inside a TransactionScope...
I mean, if you have a look at CoreBackgroundJobPerformer you will notice that there is no an extension point inside an opened ServiceScope.
However, normally I would start and commit a transaction inside a scope, roughly something like that...
Barely can we use existing job filters to start/stop a UoW, because we are not inside a DI scope of a job.
What do you think about it and do you see any problems to add two Job filters to handle this problem?