3
votes

Anyone had any luck integrating StructureMap (DI Framework) with WCF?

I can return the default instance in the constructor of my WCF service like this, but obviously it is not ideal.

public MemberService()
{
     this.memberRepository = StructureMap.ObjectFactory.GetInstance<IMemberRepository>();
}

I have seen this (http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/07/29/integrating-structuremap-with-wcf.aspx) but have not had luck setting it up as I think it's incompatible with the latest 2.5+ release of StructureMap.

1
I know this is an old post, but ranks at the top of google search still. I just put together a sample, someone might find useful in the future? github.com/house9/SampleWcfClientWithStructureMap - house9
I was able to get WCF and StructureMap to work with the lostechies article you linked to - JeremyWeir

1 Answers

5
votes

This has already been discussed here. What issues did you encounter with the example you provided? Instead of writing the code in the constructor of the service you write it in the GetInstance method of your IInstanceProvider implementation.