I am not a Ninject expert, but as far as I know, I use it only to reference my DataSource Interface and my EfDb Class to the rest of my application.
If you need a good book that has a real application built around Ninject , try: Pro ASP.NET MVC 3 Framework, third edition
or
Pro Asp.Net Mvc 4
There are very few lines of code that I usually relate to
public class NinjectControllerFactory : DefaultControllerFactory { private IKernel ninjectKernel; public NinjectControllerFactory() { ninjectKernel = new StandardKernel(); AddBindings(); } protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType) { return controllerType == null ? null : (IController) ninjectKernel.Get(controllerType); } private void AddBindings() { ninjectKernel.Bind<IDataSource>().To<EfDb>(); } }
Then register your NinjectControllerFactory in Global.asax.cs with:
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory());
As you can see, this class uses Method Injection using private void AddBindings() . This makes it very easy if you follow Test Driven Development (TDD)
Komengem
source share