Using the code found on this blog post: http://scottdorman.github.io/2016/03/17/integrating-asp.net-core-dependency-injection-in-mvc-4/ results in Scoped Services that are really Singletons, because CreateScope() is never called.
Are there any examples of using Microsoft.Extensions.DependencyInjection (M.E.DI) with ASP.NET 4?
The reason why I want to use M.E.DI instead of SimpleInjector, Autofac, Ninject, etc. is because we have a customer-facing app that is built on ASP.NET Core and uses Identity. Then we have an existing "back-office" app that already does a bunch of stuff, one of them being manage users for the customer-facing app.
We wanted to use M.E.DI so we can share the configuration of things like UserManager between the two applications easily. Also handwiring up all the dependencies that ASP.NET Core Identity has is non-trivial, and want to get the free updates in case new services are required in future updates that services.AddIdentity takes care of.
Thanks!
You need to do what all of the other DI containers did back in these times, add a module that creates a scope per request using a module and then using HttpContext.Current to get access to the scoped provider for resolving services:
Single file for brevity
https://gist.github.com/davidfowl/563a602936426a18f67cd77088574e61
Thanks @davidfowl! This is awesome!
Most helpful comment
You need to do what all of the other DI containers did back in these times, add a module that creates a scope per request using a module and then using HttpContext.Current to get access to the scoped provider for resolving services:
Single file for brevity
https://gist.github.com/davidfowl/563a602936426a18f67cd77088574e61