Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unity or unity.mvc4 for MVC4 application

I wanted to add DI to my class library which is part of MVC4 web application. So I had the option of Unity, structuremap, ninject. I chose unity because it was mentioned in Asp.Net sample.

When I searched Nuget for Unity I see there are multiple variation of Unity. Which one is suitable for my library, Unity or Unity.MVC4

like image 594
Ron Avatar asked Aug 15 '13 19:08

Ron


2 Answers

You will want to add the Unity.MVC4 package, since it provides the integration between Unity and ASP.NET MVC 4. However, Unity.MVC4 depends on Unity, so by adding that you will get both packages.

You will also need something like this to configure the integration:

var container = new UnityContainer();
// configure container here (RegisterType, etc.), then make sure MVC 4 uses Unity...
DependencyResolver.SetResolver(new Unity.Mvc4.UnityDependencyResolver(container));
like image 112
Mark Avatar answered Oct 04 '22 16:10

Mark


You should use NuGet to install Unity BootStrapper for ASP.NET MVC. It is created by Microsoft and uses the latest Unity 3.0. It is also mentioned in Developer's Guide to Microsoft Unity in page 45.

I tried Unity.MVC4 today. The current 1.2 version still uses Unity 2. Maybe the next version will use the new Unity 3.0. I guess that both should be ok then.

like image 43
Ying Avatar answered Oct 04 '22 16:10

Ying