Using Funq with Prism

May 9, 2010 at 3:05 AM

I'm attempting to replace unity with Funq within a prism implementation.

I've created a Funq bootstrapper for Prism and now I need to implement the IServiceLocator interface.

I'm a bit lost. How do I retrieve an instance based on a Type using Funq?


Here is an Ninject implementation of IServiceLocator:


public class NinjectServiceLocatorAdapter : ServiceLocatorImplBase {

 private readonly IKernel kernel;

public NinjectServiceLocatorAdapter(IKernel kernel) {

 this.kernel = kernel;
ServiceLocator.SetLocatorProvider(() => this); }

protected override object DoGetInstance(Type serviceType, string key) {

 return this.kernel.Get(serviceType);



protected override IEnumerable<object> DoGetAllInstances(Type serviceType) {

var service = GetInstance(serviceType);
return service == null       ? new object[] {}       : new[] {service};



How would I implement these 2 methods using Funq?

Thanks in advance.

May 9, 2010 at 5:31 AM

DoGetinstance would require thatyou make up the generic method in Funq to invoke using reflection (i.e. something like container.GetMethod("Resolve").MakeGenericMethod(serviceType)) and then invoke it.