Skip to content
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

Register activities with DI and allow the lifetime to be defined #1413

Open
sclarke81 opened this issue Nov 26, 2024 · 1 comment
Open

Register activities with DI and allow the lifetime to be defined #1413

sclarke81 opened this issue Nov 26, 2024 · 1 comment
Assignees
Labels
area/workflow kind/enhancement New feature or request
Milestone

Comments

@sclarke81
Copy link

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: #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.

@WhitWaldo WhitWaldo self-assigned this Nov 26, 2024
@WhitWaldo WhitWaldo added this to the Future milestone Nov 26, 2024
@WhitWaldo
Copy link
Contributor

We don't have a milestone for v1.16 yet, so I've tagged this Future for now, but I'll revisit when that changes after the 1.15 release.

@WhitWaldo WhitWaldo added the kind/enhancement New feature or request label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/workflow kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants