Use unresolved unity

2

I would like to know if there is any way to use unity with the configuration of its records in an external library and this is added to my web project or console, and when the project controllers receive an interface as parameters are resolved.

The idea is that I do not want to use Unity.MVC because I would be marrying a presentation layer. But to do something generic whatever the type of application in the presentation.

    
asked by Norberto Quesada 16.05.2016 в 21:20
source

1 answer

1

As all these libraries are open source you can analyze the code found in the GitHub repository of Unity.Mvc5 and study how they implement it to be able to adapt it to your need. This way you copy the code without having a dependence to the library.

The definition of UnityContainer and type records can be done in a separate library

var container = new UnityContainer();
container.RegisterType<IxxService, xxService>();

But the important point is how do you define the DependencyResolver

DependencyResolver.SetResolver(new UnityDependencyResolver(container));

When you use your own implementation, but it's at that point where you help Unity.Mvc

[ASP.NET MVC] Injecting dependencies with Microsoft Unity

    
answered by 16.05.2016 в 21:46