Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity.Mvc vs Unity.Mvc5 differences

I just started to learn ASP.NET MVC 5 and found a lot of tutorials about using the Unity ioc container for dependency injection.

I followed this great video to start: https://www.youtube.com/watch?v=E7Voso411Vs

when looking for the package to install, I saw:

enter image description here

I found this tutorial from October 2014 that shows how to use the Unity.Mvc framework. All it required is:

  1. adding the package (automatically adding UnityConfig.cs and UnityMvcActivator.cs to App_Start.
  2. create interface (IUnitySample for example) and an implementation
  3. adding a constructor to HomeController for example that takes a IUnitySample as a parameter.
  4. and finally, add to UnityConfig.cs in method RegisterTypes the register statement: container.RegisterType<IUnitySample, UnitySample>();

No need to add anything in Application_Start method.

That seems very easy and it works, but from the more updated tutorials I read, it shows that people are using the Unity.Mvc5 package and not the Unity.Mvc.

What should I use to learn ASP.NET MVC 5? what are the differences between them? is one better than the other?

like image 387
Ofek Agmon Avatar asked Oct 24 '25 05:10

Ofek Agmon


2 Answers

Unity.Mvc5 and Unity.Mvc are created by two different organizations and have different implementations.

Unity.Mvc5 creates a child container per web request. This works well with the built-in HierarchicalLifetimeManager.

Unity.Mvc does not create a child container, but instead chose to create a new LifetimeManager called PerRequestLifetimeManager.

like image 90
Renat Zamaletdinov Avatar answered Oct 26 '25 23:10

Renat Zamaletdinov


Personally, I consider Unity.Mvc a better choice for its statistics (e.g .: total downloads) and because it shows a higher frequency of updates in the "Version History". Therefore it seems to be more followed.

like image 27
Tyler Durden Avatar answered Oct 26 '25 22:10

Tyler Durden