I have split this guide into two sections. The first section is for people who just don't remember which classes to use to set up depedency injection. The other is how to set the dependency injection up without any prior knowledge.
Setting up the dependency resolvers##
If you are just looking for a way to set the resolver in a MVC project it can be done in the following way:
var container = new UnityContainer(); DependencyResolver.SetResolver(new Microsoft.Practices.Unity.Mvc.UnityDependencyResolver(container));
For a Web API project it is done in the following way:
var container = new UnityContainer(); GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
They can easily be combined and you can use the same container for both resolvers. The dependency resolver is often set in the global.asax.cs file in the Application_Start method.
The easiest way to install unity - in my oppinion - is to use the package manage console. It can be found here in Visual Studio:
Tools > Nuget Package Manager > Package Manager Console
In the package manager console type the following and hit enter:
Depending on whether you need MVC, WebApi or both, you can run the following commands:
If you do not wish to use nuget you can also download unity from here. Then reference the dll(s) in your project.
You now have unity installed into your project!