Please find the code for configuring Unity container. Also please ensure that you have <unity> section in your web config where you would register your types
Ensure that you take a static container variable so that it is available for all request
public static IUnityContainer container;
Below code should be present in Global.asax.cs Application_Start method
container = new Microsoft.Practices.Unity.UnityContainer();
UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Containers.Default.Configure(container);
or if you are not using config use below code to register type
container.RegisterType<interface,class>();
Also add below code in prerequest handler so that your types are build by the container
protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
{
IHttpHandler httpHandler = HttpContext.Current.Handler as System.Web.UI.Page;
if (httpHandler != null)
{
if (unityContainer != null)
{
unityContainer.BuildUp(httpHandler.GetType(), httpHandler);
}
}
}
Web.config changes
Add a new section for unity
<configsections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
</configsections>
and then defines the unity section
<unity>
<containers>
<container>
<types>
<type type="Full Interface Name including Namespace, Assembly Name" mapto="Full class Name including Namespace, Assembly Name">
</type>
</types>
</container>
</containers>
</unity>