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
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));
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With