Exemplo n.º 1
0
 protected override async Task RunAsync(Execution <HandleContext> execution)
 {
     using (IServiceScope scope = ioc.CreateScope())
     {
         execution.Context.AssignPropertySafely <IWorkflowContextWithServiceProvider>(prop => prop.ServiceProvider = scope.ServiceProvider);
         ILogger <ScopedMessageWorkflow> logger = scope.ServiceProvider.GetRequiredService <ILogger <ScopedMessageWorkflow> >();
         if (EnsureTenantIsSet(scope, execution.Context.Message))
         {
             using (logger.BeginScope(scope => scope
                                      .AddScope("cronus_tenant", execution.Context.Message.GetTenant())))
             {
                 scopes.AddOrUpdate(execution.Context, scope, (c, s) => scope);
                 try
                 {
                     await workflow.RunAsync(execution.Context).ConfigureAwait(false);
                 }
                 finally
                 {
                     scopes.TryRemove(execution.Context, out IServiceScope s);
                 }
             }
         }
     }
 }