How to correctly use HttpContext.GetOwinContext (). GetUserManager ()? Do I need to wrap it in using? Or does he close the connection himself? The question arose because of the logs of the database, there is a feeling that this method breeds connections and does not close them, as a result we get a bunch of zombies of connections and a dead database.
1 answer
I answer myself. It needs to be wrapped in using, because he (or EF6) does not close the connection behind him. You can make it more elegant using Middleware in Owin. To do this, go to IdentityConfig and add the following code to the Configuration method:
app.Use(async (context, next) => { await next(); context.GetUserManager<AppUserManager>().Context.Dispose(); });
PS I keep DbContext in AppUserManagar'e, you may not have it.
|