Search code examples
.netasp.net-mvcasp.net-mvc-3dependency-injectioninversion-of-control

DefaultControllerFactory vs IDependencyResolver


I have a little misunderstanding: when we implement IDependencyResolver it means that we can use DI for every part in the project. So even if i don't inherit from DefaultControllerFactory i can build controllers regestering dependencies?

edits: i recommend look through all these Brad Wilson's posts
also this post is useful


Solution

  • Pedant note first. You cannot inherit from an interface (IDependencyResolver) but I assume you mean implement.

    In short you have a choice between using either, you would not use both. So if you have the resolver set up you do not need to have a controller factory and vice versa.

    I have only used DefaultControllerFactory in mvc with castle-windsor. You will need to be wary of one loose end in using IDependencyResolver if you are using castle-windsor also, there is no release method but there are probably ways around this.

    With other frameworks such as ninject or unity IDependencyResolver is sometimes preferable.