Closed raphael-m closed 7 years ago
According to research by @raphael-m this seems to be an Entity Framework Core issue. Some object seems to keep an open connection to the DB, till a ToList happens.
The temporary fix should prevent the issue. Some background information:
ServiceProvider
has a private List<IDisposable> _transientDisposables;
ServiceProvider
as a static variable, which causes that all ever resolved (disposable) dependencies are kept in memory and are not being disposed.ServiceProvider
should be automatically disposed after a request finishes (which in turn disposes all _transientDisposables
) [source]@raphael-m I think you missunderstood the asp.net core scenario. AFAIK the ServiceProvider is not disposed, but the DB-object is "scoped" not "transient", so it never goes to _transientDisposables
but is kept till the request completes, then removed.
In our case, using scoped actually makes the DI very slow for reasons unknown. The page gets dramatically slower in that case. This is why I switched from scoped to transient. My guess is that in asp.net full, the DI doesn't know about the scopes. Apparently there are manual ways to start/stop a scope, but I'm not sure where the ideal hook for this would be, so I would be very careful about that...
Edit Pls also check http://www.inversionofcontrol.co.uk/asp-net-core-1-0-dependency-injection-what-is-is-and-what-it-is-not-2/
Edit 2 Note that I'm also experimenting with this in the factory.cs - we'll have to test it with your test-code:
return _sp.CreateScope().ServiceProvider;
After saving some entities, an error message appears:
All 2sxc modules stop working until the application is restarted. 2sxc version: 9.1.2