I’m putting the unity container creation/setup in the global.asax. and making the container a static property on that class since i’m not sure how unity works or if the container needs to be kept alive and references elsewhere. What’s the recommended location of unity initialization/configuration for mvc 2?
I’m putting the unity container creation/setup in the global.asax. and making the container a
Share
You shouldn’t need to keep an explicit reference around for the container. A container should wire up the requested object graph (Controllers in this case) and get out of the way.
Take a look at the container-specific implementations of IControllerFactory in MVCContrib.
That said, I like the WindsorControllerFactory a lot better than the UnityControllerFactory, but you could implement a UnityControllerFactory that uses the same pattern (Constructor Injection) as the WindsorControllerFactory.
If you imagine that we do that, your Global.asax should look like this:
controllerFactoryholds a reference to the container, so you can let it go out of scope in Application_Start – it’s going to stay around because the ControllerFactory stays around.