-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issues(4918): fix resolve scoped service for Elsa.MongoDb.Modules #4924
Conversation
Your PR makes sense, and I think we can get by with a single scope that we create first and then pass down to the individual "create indices" methods. What do you think? |
I agree this is the correct way |
@@ -8,9 +8,9 @@ namespace Elsa.MongoDb.Modules.Identity; | |||
|
|||
internal class CreateIndices : IHostedService | |||
{ | |||
private readonly IServiceProvider _serviceProvider; | |||
private readonly IServiceScope _serviceScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I am not 100% sure, but if this hosted service remains in memory, so does this child service scope. Therefore, perhaps it is better to not store the child scope asa private field, but rather as a temporary local variable that gets disposed when done with.
E.g.
private readonly IServiceProvider _serviceProvider;
public CreateIndices(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
public Task StartAsync(CancellationToken cancellationToken)
{
using var scope = _serviceProvider.CreateScope();
return Task.WhenAll(
CreateWorkflowDefinitionIndices(scope, cancellationToken),
CreateWorkflowInstanceIndices(scope, cancellationToken));
}
issues(4918): scope service by instance CreateIndices
c5be7b1
to
8a6a29a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍🏻
Releated to this issues: #4918