-
Notifications
You must be signed in to change notification settings - Fork 317
Connection Leak with DI #584
Comments
This should be a singleton. As for the other objects.. What is a DbShardContextFactory? How does the |
Sorry that is a typo, they are meant to be the same, i was trying to clean code up for example. The DbShardContextFactory is responsible for providing a SqlConnection obj to the constructor of the ConXDbContext, it parses the request and maps a connection to a shard from the subdomain, previously it created and returned the new ConXDbContext but reading the ASP.NET Core docs because it wasnt created by the DI container it wont be disposed. Thanks for your time :) |
I inlined the wire up here to avoid going back to the link. What's not getting disposed? |
I believe that the other repositories are being disposed in a "Scoped" fashion as expected. |
I have resolved this issue by migrating to AutoFac, to use the InstancePerLifetimeScope and constructor resolution as EF needs the design time opts which lead to an ambiguous constructor error, then i am manually closing the connection in the DbShardContextFactory because even though the Dispose method is being called the connection was not closing. |
This issue was moved to dotnet/aspnetcore#2335 |
issuelink
I am using a single tenant config where i need to route to a customer shard based on the request. The DbShardContextFactory does this with help from the HttpContextAccessor.
Because the factory creates the DbContext instead of the DI Container it appears to not be disposing correctly even though defined as Scoped. so the .AddEntityFrameworkStores<ConXDbContext>()
call i believe is the issue
What is the correct pattern here to use the standard ASP.NET Core service collection?
I am having trouble defining the right pattern to use here, we are just migrating and what was previously working in Ninject .InRequestScope() is not the same with the in built DI.
What would be the functional equivalent pattern here?
The text was updated successfully, but these errors were encountered: