How do I use Structure开发者_运维知识库Map 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?
The method in the previous example article can be made to work by:
- deriving
StructureMapServiceHost
fromWebServiceHost
and notServiceHost
- deriving
StructureMapServiceHostFactory
fromWebServiceHostFactory
and notServiceHostFactory
The benefit of this? No web.config changes required. It's all done programatically.
In addition to Alex's instruction, you need to wire up your ServiceHostFactory
in the service route of your service instead of using WebServiceHostFactory
.
RouteTable.Routes.Add(new ServiceRoute("MemberProvisioning/Api", new IoCServiceHostFactory(), typeof(MemberService)));
Hope this helps.
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.
精彩评论