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

1

0

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();
Exscind answered 2/6, 2014 at 9:55 Comment(3)
possible duplicate of Ninject UserManager and UserStoreCrystlecs
@Crystlecs this was my question. The answer is correct, but I don't know how to inject UserStore and UserManager into controller!Exscind
I think that you must retrieve the bound objects at single top-level factory (or master controller) and pass it through consumer classes (using constructor or property injection).Crystlecs
D
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.

Darsey answered 2/6, 2014 at 11:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.