views:

51

answers:

2

How do I use StructureMap in a WCF 4.0 REST service?

I've used StructureMap in the past using this article but the technique doesn't seem to work with the WebServiceHostFactory(). What's the secret?

A: 

I got it to work following this example. Essentially you write a customer BehaviorExtension instead of a ServiceHostFactory and life is good.

Would still appreciate any understanding as to why using a custom WebServiceHostFactory doesn't work. It appeared to wire everything up correctly but my IInstanceProvider's GetInstance() method was never being called.

roufamatic
A: 

The method in the previous example article can be made to work by:

  • deriving StructureMapServiceHost from WebServiceHost and not ServiceHost
  • deriving StructureMapServiceHostFactory from WebServiceHostFactory and not ServiceHostFactory

The benefit of this? No web.config changes required. It's all done programatically.

Alex