2

I was looking over the Ninject MVC source code, and the method that generates a controller factory for overwriting the default is hardcoded to only return a NinjectControllerFactory, however as its set as virtual it would make more sense (in my eyes) to use an IControllerFactory.

/// <summary>
/// Creates the controller factory that is used to create the controllers.
/// </summary>
/// <returns>The created controller factory.</returns>
protected virtual NinjectControllerFactory CreateControllerFactory()
{
    return new NinjectControllerFactory(this.Kernel);
}

I love Ninject and I am sure there is a reason why it was done this way, but have a problem at the moment where I need to write my own ControllerFactory and use that, but would rather still use the NinjectHttpApplication. I know I could just inherit from NinjectControllerFactory and then override the method to return this new instance, but I would not be using any functionality from the Ninject flavour so it just seems that it would be a bit of a smell...

So is there a reason why it doesn't use IController or is this something that may be changed in the new version?

Grofit
  • 17,693
  • 24
  • 96
  • 176

1 Answers1

1

I assume that you are refering either to MVC 1.0 or 2.0. MVC 3.0 takes a completely different way.

No there is no reason for not returning an IControllerFactory. This was most likely just an automatic refactoring and was not recognized. On the other hand if you are not using the NinjectControllerFactory there is almost no reason to use the extension at all.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Remo Gloor
  • 32,665
  • 4
  • 68
  • 98
  • Thats odd, the source code I got for the latest build against Ninject V 2.2.0.0 still uses ControllerFactory. Unless I was an idiot and got the MVC2 version ones. Thought it was odd that you were not using a DependencyResolver. Checked source in git and realised it is not a problem now. – Grofit Dec 07 '11 at 19:50