This project is read-only.

What is registering controllers with RegisterMvcControllers() good for?

Aug 12, 2013 at 3:22 PM
why do i need/why it is usefull to register mvc controllers with container? Can anybody explain it in order to understand it well? thanks
Aug 12, 2013 at 6:12 PM
Simple Injector allows resolving unregistered concrete types, so you can resolve controllers even while they're not explicitly registered in the container. There are two important reasons however why you still should consider registering them explicitly:
  1. Due to the nature of MVC's IDependencyResolver, a misconfiguration in the container could cause MVC to hide the real reason an (unregistered) controller couldn't be resolved, and throw a "Type '...' does not have a default constructor" exception instead as explained in this thread.
  2. Not registering all root objects (objects that are resolved directly) in the container, prevents the container from having a complete picture of its configuration. This will give a false sense of security when calling container.Verify(), since that call can still succeed, while their the application can still fail at runtime when resolving a controller. Always try to have a verifiable container configuration.
Marked as answer by dot_NET_Junkie on 2/26/2014 at 1:42 PM