Ninject: Controller Constructor with int argument

Posted by Fleents on Stack Overflow See other posts from Stack Overflow or by Fleents
Published on 2010-04-23T23:00:35Z Indexed on 2010/04/23 23:03 UTC
Read the original article Hit count: 241

Filed under:

How can you instantiate a Controller that has an int argument? Using Ninject..

My HomeController has a constructor like this:


  private int _masterId;
  Public HomeController(int masterId){
       _masterId = masterId;
}

I created a controller factory like this:


public class NinjectControllerFactory : DefaultControllerFactory
    {
        IKernel kernel = new StandardKernel(new ExampleConfigModule());

        protected override IController GetControllerInstance(Type controllerType)
        {

            return controllerType == null ? null
                                          : (IController)kernel.Get(controllerType, 1);

        }

    }

© Stack Overflow or respective owner

Related posts about ninject