WCF + Service Locator

Sep 13, 2010 at 6:12 PM

Hello All,

I am fairly new to SharePoint, so pardon the "newby" question. 

I am trying to use the Service Locator and WCF services.  We have a ton of WCF services that goes against data store,  What I am trying to do is to be able to use that service locator to find those services for me.  I am doing this with the latest bits, and using SP2010. 

I have not been able to find a sample implementation. 

What I am confused on is that to register the mapping (at least this is how I done it) I have to reference the service or add it to the solution to get it to register, this does not sound like de-coupling to me. 

So my question is how do I use a WCF service with Service Locator?  Is that possible?

A sample implementation will be great.

Thanks in advance.



Sep 14, 2010 at 7:04 PM


There are a number of examples of how to use the service locator in the reference implementations.  For example you can look at the SharePointList RI that we ship, it uses the service locator to locate the repository it uses.The typical pattern is that you use an interface in your code, and you retrieve an instance for that interface where you consume the service.  In this case the service is not a web service, but a logical abstraction of a class that provides the service.  The service locator is a simple implementation of the Dependency Injection/Inversion of Control pattern implemented by DI containers like Unity, Castle, Spring, etc.

You register the mapping of the concrete type that provides a service.  This is done through configuration.  Since the consumer of the service never has to "new" up the concrete type, it is decoupled from it. 

There is a lot of specific how-to information in the online guidance at The SharePoint Service Locator.