views:

155

answers:

1

I'm working on replacing Unity with Ninject in the Prism framework. This requires me to implement a Ninject specific IServiceLocator. From what I've understood I can inherit the ServiceLocatorImplBase instead, so that's what I do. Now how can I set this to be the Current ServiceLocator? I need this in order to have e.g. the RegionManager get it when it creates regions, and calls:

IServiceLocator locator = ServiceLocator.Current;

This is a static property, but it doesn't have a setter.. There is a function:

void ServiceLocator.SetLocatorProvider(ServiceLocatorProvider newProvider);

..but the argument doesn't match my ServiceLocatorImplBase. Any ideas?

+2  A: 

The ServiceLocatorProvider is a delegate, you can do this:

var container = NInjectServiceLocator(); // your ServiceLocatorImplBase impl.

ServiceLocator.SetLocatorProvider(() => container);
Steven
Thanks! Works perfectly!
stiank81
If you want to know what's the advantage for the `SetLocatorProvider` method over a `Current` setter method, read this discussion: http://commonservicelocator.codeplex.com/Thread/View.aspx?ThreadId=50463.
Steven