How do I let Ninject inject dependencies into my MVC controllers?

折月煮酒 提交于 2019-12-12 04:46:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!