Register activities with DI and allow the lifetime to be defined
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 378
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 6
Description
I've been talking to @WhitWaldo on Discord about being able to use activities with a scoped lifetime. The root of this for me was a library I'm using is trying to get the `HttpContext` using `IHttpContextAccessor` and the context is null.
This led to this PR: https://github.com/dapr/dotnet-sdk/pull/1408
However, I think for this change to work fully I think we'd have to change the way activities are registered. Currently it's adding an activity to the durable task registry using a factory function. The function we pass in calls `ActivatorUtilities.CreateInstance` to create the instance of the activity. It looks like the factory is used so that the activity can be wrapped with the `ActivityWrapper`. I think instead the activity could be registered with DI with the correct scope and then use `ActivatorUtilities.GetService` in the factory. It'd mean passing the scope into the WorkflowRuntimeOptions as well.
I'm not sure if there would be any repercussions to doing this.
Contributor guide
Assessment
This issue has not been assessed yet.