I have the following two classes. The ninject web common:
public static class NinjectWebCommon { private static readonly Bootstrapper bootstrapper = new Bootstrapper(); /// <summary> /// Starts the application. /// </summary> public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); } /// <summary> /// Stops the application. /// </summary> public static void Stop() { bootstrapper.ShutDown(); } /// <summary> /// Creates the kernel that will manage your application. /// </summary> /// <returns>The created kernel.</returns> private static IKernel CreateKernel() { var kernel = new StandardKernel(); try { kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); RegisterServices(kernel); GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); return kernel; } catch { kernel.Dispose(); throw; } } /// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { kernel.Bind<ITest>().To<Test>(); } }
My controller class:
public class AllCarPartController : MainController<AllCarPart, AllCarPartViewModel, E1Entities> { private ITest _test; public AllCarPartController() { } public AllCarPartController(IMemoryCache memoryCache , ITest test) : base(memoryCache) { _test = test; } } public interface ITest { void TestMe(); } public class Test : ITest { public void TestMe() { } }
When I call the controller, the parameter less constructor is being called and the other constructor with the interfaces is not called, so my instance of ITest is always null.
What is wrong?