I have about 6 WCF services that I want to host in an MVC application , routing requests on /services/foo to WcfFooService and /services/bar on WcfBarService
I can do IoC using StructureMap in services and inject my constructor dependencies using the example that Jimmy Bogard wrote about here :
Jimmy's article is great, but I'm trying to extend it to work with several services hosted in the same MVC application . In fact, the part below is the part that causes me some headaches:
public class StructureMapServiceHostFactory : ServiceHostFactory { public StructureMapServiceHostFactory() { ObjectFactory.Initialize(x => x.AddRegistry<FooRegistry>());
Using the WCF single service service - routing MVC requests to a specific URL through StructureMapServiceHostFactory shown above works brilliantly - but - if (for example) I create StructureMapServiceHostFactory2 to call /services/bar to allow the use of a different registry when the MVC application spins , it, in turn, calls each factory when it starts through RouteConfig.cs and adds routes, so in the end I do not get the configured instances that the first ServiceHostFactory should provide.
It doesnโt matter if I call Initialize(); or trying to grab the Container property and call Configure on it.
Am I hiding something from this? The main reason for the need to isolate the registry is due to a different NHibernate configuration, but I can configure named instances of SessionFactory and Session for NHibernate, and then use one registry to get around this. In my opinion, I wanted the WCF service and MVC hosting to be able to isolate their IoC containers, so I went along this route.
Is there a way I can do this?
source share