Now, the problem is that some services need the user identity of the original request. Or at least some claims from there.
Is there any way that I can register dependencies with the newly created scope?
Like, I have two classes implementing an interface, say, IUserNameProvider, and one has the claims identity as constructor parameter, and one the username, and I want the one class to be used in a normal call, and the other in an independent scope.
I was hoping to be able to register the other provider as singleton instance in that other scope.
Is something like that possible? If not, is there a recommended way of doing it?
None
0 Points
1 Post
Dpendency injection for background jobs
Dec 04, 2019 04:43 PM|Volker Hetzer|LINK
Hi!
I'm doing a backgound job listening to a queue as per doc: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.1&tabs=visual-studio#consuming-a-scoped-service-in-a-background-task
Now, the problem is that some services need the user identity of the original request. Or at least some claims from there.
Is there any way that I can register dependencies with the newly created scope?
Like, I have two classes implementing an interface, say, IUserNameProvider, and one has the claims identity as constructor parameter, and one the username, and I want the one class to be used in a normal call, and the other in an independent scope.
I was hoping to be able to register the other provider as singleton instance in that other scope.
Is something like that possible? If not, is there a recommended way of doing it?
All-Star
58144 Points
15646 Posts
Re: Dpendency injection for background jobs
Dec 04, 2019 05:08 PM|bruce (sqlwork.com)|LINK
the user identity should be passed via the queue request, not injected via constructor.