How to set my implementation of IServiceLocator as ServiceLocator.Current?

I am working on replacing Unity with Ninject in a Prism framework. This requires me to implement a specific IServiceLocator for Ninject. From what I understood, instead I can inherit ServiceLocatorImplBase so that I do it. Now, how can I set this as Current ServiceLocator? I need this to have, for example, a RegionManager gets it when it creates regions, and calls:

IServiceLocator locator = ServiceLocator.Current; 

This is a static property, but it does not have a setter. There is a function:

 void ServiceLocator.SetLocatorProvider(ServiceLocatorProvider newProvider); 

.. but the argument does not match my ServiceLocatorImplBase. Any ideas?

+4
source share
1 answer

ServiceLocatorProvider is a delegate, you can do this:

 var container = NInjectServiceLocator(); // your ServiceLocatorImplBase impl. ServiceLocator.SetLocatorProvider(() => container); 
+4
source

Source: https://habr.com/ru/post/1306687/


All Articles