What is the recommendation from DTF on Dependency Injection on ServiceCollection - to use AddTransient or to use AddScoped for Orchestrations/Activities?
Closed this issue · 1 comments
We are currently implementing a use case using DTF where we are using ObjectCreator to initialize orchestrations and activities with dependency injection.
We read that AddTransient could be a problem while registering orchestrations/activities here%0A%7B%20...%20%7D):
What we are currently doing is this?
ServiceCollection collection = new ServiceCollection();
collection.AddTransient<Orchestrator1>();
collection.AddTransient<Activity1>();
//code to create invoke ObjectCreators
Should this be changed to below instead?
collection.AddScoped<Orchestrator1>();
collection.AddScoped<Activity1>();
Most examples and blogs suggest using transient but is there an official guidance on this?
@cgillum any recommendations?
There is no single answer to this. Your business logic of the individual classes will be the deciding factor - we cannot tell you what to do as we do not know your classes.
I will say that the stackoverflow link is not entirely accurate - there is nuance to what the service container disposes. Here is some documentation on this: https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection-guidelines#disposal-of-services
Closing as this question is not something we (as the Durable Framework) can answer.