-
Some times when I need a scoped service from a singletone service, I have to manually get the tenant level service provider first using below code
Then use the tenant level service provider to get scoped service. It looks verbose. Has a way to inject the tenant level service provider into constructor then it can be used directly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you are sure that your method is called in a scope context
In a more aspnetcore way you can inject Otherwise if the method is not called in a scope context you should create a scope by using
|
Beta Was this translation helpful? Give feedback.
If you are sure that your method is called in a scope context
In a more aspnetcore way you can inject
IHttpContextAccessor
to retrieve the currentRequestServices
. A request context is not the same as a scope context (here the scope of a given tenant / shell) but we take care in a given request thatRequestServices
is set to the scope service provider of the tenant / shell on which the request was done.Otherwise if the method is not called in a scope context you should create a scope by using
GetScopeAsync()
, notice that in…