Install Unity Container in Visual Studio

Here, we are going to install Unity container in Visual Studio using NuGet.

First of all, we need to create a project in order to use Unity. It can be any type of project such as class library, console, web, windows or any other C# or VB.NET project. We will create a Console Application to demo Unity container. So, click on New Project from the Start page of Visual Studio. It will open New Project popup as below.

Install Unity Container in Visual Studio

Enter Name of the project and location as per your choice and click OK. This will create new console application project.

Now, we need to install Unity in this project because we want to dependency injection in our project. So, right click on the project node in the solution explorer and select Manage NuGet Packages as shown below.

Install Unity Container in Visual Studio

Now, we can search for unity from the browse tab of NuGet. Enter "unity" in the search box and it will list all the libraries or plugins which contains "unity" word as shown below.

Install Unity Container in Visual Studio

Now, click on Install button in the right pane as shown below.

Install Unity Container in Visual Studio

This will add all the references of unity into your project as shown below.

Install Unity Container in Visual Studio

So now, we are ready to use Unity to implement automatic dependency injection in our project.