One way to do this, which I often do for convenience, is to declare your container as a global variable in the Global.ascx.cs file, for example:
public class MvcApplication : System.Web.HttpApplication { public static UnityContainer Container; protected void Application_Start() {
However, this is pretty hack-ish.
The right thing is to use Unity to resolve your controllers ( See this article about creating a factory unity controller ) and then allow the unit to inject any dependencies into your controller when it decides the controller.
So a controller like:
public MyController: Controller { public ICacheManager CacheManager {get;set;} }
Automatically recognizes any dependencies that your container has registered.
source share