Welcome to the Common Service Factory library
The Common Service Factory library contains Windows Communication Foundation (WCF)
service factory implementations built on top of the Common Service Locator
library. Using the library allows for the Dependency Inversion Principle
to be applied to WCF services while using the IoC container of your choice, as long as there is a Common Service Locator adapter available. The library contains factory implementations for both SOAP and RESTful services.
How it works
The library implements a custom IInstanceProvider implementation, which uses the Common Service Locator to get a reference to an Inversion of Control container. The container is then queried for an instance of the requested service type. The instance provider is dynamically injected as an endpoint behavior to all of the endpoints with a matching service contract.
1 There needs to be an adapter for the Common Service Locator available for the IoC container that you are using in order for it to work with the Common Service Factory library. If there isn't one available, then you should contact the author(s) of the IoC container and ask them to implement one
- Download the latest release of the Common Service Factory library
- Download the latest release of the Common Service Locator library and the adapter for the IoC container that you are using
- Add a reference to the CommonServiceFactory.dll, Microsoft.Practices.ServiceLocation.dll and the assembly that contains the adapter for your IoC container
- Edit the .svc file for your service so that Service attribute contains the Assembly-Qualified Name of the service type
- In the .svc file, add the Factory attribute and provide the Assembly-Qualified Name of on of the factories that are available (ServiceHostFactory for SOAP services and WebServiceHostFactory for RESTful services) in the Common Service Factory library
- Configure your IoC and setup the Common Service Adapter
- Enjoy using loosely coupled dependencies in your WCF services using the IoC container you prefer1
- Common Service Locator, needed to configure an IoC container adapter that is going to be used by the factories