Closed Madajevas closed 8 months ago
@Madajevas
Hi, I did not look at WebAPI for a long time and I don't remember who is responsible for disposing the scope.
From the code alone, I see that the framework should supposedly call the IDependencyScope scope = DryIocDependencyResolver.BeginScope()
.
And at end of request the scope should be disposed via scope.Dispose()
.
So, in principle, those methods should be hooked and called somewhere. I don't know where.
Yup. My debugging led me to the same conclusion: there is a resolver adapter (DryIocDependencyResolver
) which, when framework calls BeginScope
returns scope adapter (DryIocDependencyScope
). When request is done processing Dispose
method is indeed called on adapter and delegated to scope created. Anyway, in reality Dispose method in dependency is not invoked. Any suggestions how I could get to the bottom of this?
Maybe try to search for DryIoc WebApi examples.
Got a bit further. If instance of HttpContextScopeContext
is passed to WithWebApi
registration, code gets to scope disposal, however disposables are recognized as ImHashMapEntry
and .Disposed
is called on controller, not service it depends on:
@Madajevas HttpContextScopeContext
is available through the DryIoc.Web extension. It is separate from the DryIoc.WebApi. But you may use them together.
ImHashMapEntry
It is just an implementation detail which stores the disposables.
Hey. I have the following in .NET 4.8 WEB API project:
New instance of
TheDependency
gets created and injected intoValuesController
each time controller is necessary, however, once request is finishedDispose
is never called onTheDependency
. If scope is created and disposed manually (as inGet
action with parameter) andTheDependency
get resolved using that scope,Dispose
is invoked.Shouldn't disposable dependencies be disposed when web request scope is being disposed? What am I missing? DryIoc.WebApi.dll v5.0.0 is used.