You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which is an improvement of the previous implementation (using the global scope) however it comes with a drawback:
Let's say I've registered a scoped service that uses a database connection and stores cache in a field.
When I resolve the service in control A, the instance is created and the data is cached.
When I resolve the same service in control B, it's creating a new instance because it's a different scope. The service retrieves the same data again.
Description of solution
In #3520@dimarobert created HttpContext.Current.GetScope(). I would suggest to use the same scope in PortalModuleBase and if the HTTP Context doesn't exists, then it would create a new scope.
Description of problem
In the class
PortalModuleBase
it is possible to resolve services through the propertyDependencyProvider
.In PR #3930 the implementation changed which causes every control to have its own scope:
Dnn.Platform/DNN Platform/Library/Entities/Modules/PortalModuleBase.cs
Line 46 in 8bb34af
Which is an improvement of the previous implementation (using the global scope) however it comes with a drawback:
Let's say I've registered a scoped service that uses a database connection and stores cache in a field.
Description of solution
In #3520 @dimarobert created
HttpContext.Current.GetScope()
. I would suggest to use the same scope inPortalModuleBase
and if the HTTP Context doesn't exists, then it would create a new scope.Additional context
In ASP.Net Core, scoped services are created per request (see https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection#request-services). So I assumed this was also the case in DotNetNuke.
Workaround
It's possible to use
Context.GetScope().ServiceProvider
instead ofDependencyProvider
to use the request scope.The text was updated successfully, but these errors were encountered: