问题
How do you inject UserManager and UserStore into a controller? Ninject bindings are:
kernel.Bind<ApplicationDbContext>().ToSelf().InRequestScope();
kernel.Bind(typeof(UserManager<>)).ToSelf().InRequestScope();
kernel.Bind(typeof(UserStore<>)).ToSelf().InRequestScope();
回答1:
To be able to auto-wire MVC controllers, you need to either replace MVC's default IControllerFactory
or the default IDependencyResolver
. There's a Ninject.MVC3 Nuget package that implements a dependency resolver for you. You can more information about how to integrate Ninject with MVC on this Ninject integration page.
来源:https://stackoverflow.com/questions/23991796/how-do-i-let-ninject-inject-dependencies-into-my-mvc-controllers