This may be stupid question, but I am looking at Ninject sources and don't see NInject registering its own controller factory. I also don't see any IControllerFactory
class in Ninject.Web.Mvc
assembly. Am I missing something? How does Ninject create controller and inject parameters into constructor?
DefaultControllerFactory
, the same as non-Ninject applications. DefaultControllerFactory
finds type for controller (TaskController
).DefaultControllerFactory
has internal class called DefaultControllerActivator
. DefaultControllerActivator
has method called Create
, which returns controller instance. DefaultControllerFactory
asks DefaultControllerActivator
for TaskController
type instance.DefaultControllerActivator.Create
uses IDependencyResolver
. This is where Ninject
comes in. Since Ninject
implements its own resolver and sets it at the start of application, he gets request for TaskController
instance.Ninject
finds constructor for this type, injects parameters, returns controller instance.