I registered unity container like this:
var container = new UnityContainer();
container.RegisterType(new Containe
One way of doing this which I often do for convenience is to declare your container as a global variable in your Global.ascx.cs file like:
public class MvcApplication : System.Web.HttpApplication
{
public static UnityContainer Container;
protected void Application_Start()
{
// assuming your initialize here
}
}
However this is fairly hack-ish.
The correct thing to do would be to use Unity to resolve your Controllers (See this article on creating a unity controller factory), and then allow unity to inject any dependencies into your controller when it resolves the controller.
So a controller like:
public MyController: Controller {
public ICacheManager CacheManager {get;set;}
}
Would automagically resolver any dependencies that your container has registered.