Using the Common Service Locator and Unity is fairly simple with Nuget. This post records the steps in case I need them again.
- Add the CommonServiceLocator and Unity packages to the project using Nuget.
- Add the following initialisation code (for example in Application_Start):
UnityContainer container = new UnityContainer();
//configure container
...
var unityServiceLocator = new UnityServiceLocator(container);
ServiceLocator.SetLocatorProvider(() => unityServiceLocator);
- Use the IServiceLocator and ServiceLocator interface and class for DI and service location, respectively.
No comments:
Post a Comment