inversion-of-controlwebservicehost

IoC Containers, WCF & ServiceHostFactories


I have been reading about IoC lately, and I think it would definitely come in handy in the WCF web-service I am developing. However, it seems that Ninject, StructureMap and Spring.Net (I only did check these three) require the custom Factory attribute to be added to the *.svc file:

<%@ ServiceHost Language="C#" Debug="true" Service="SomeService" CodeBehind="SomeService.svc.cs" Factory="Ninject.Extensions.Wcf.NinjectServiceHostFactory" %>

The problem is that, due to the architecture of the system where the service will be deployed, I am already using a custom factory which is a must-have (a requirement) for this project. Can I somehow overcome this situation?


Solution

  • Autofac also uses a custom factory, and I suspect they all will since this gives the IoC container a chance to be involved in the service creation process. Most (all?) of these are open source, so you might want to browse their source code and see if it would be possible to wrap the IoC custom factory in yours, or modify the source to integrate them.