views:

886

answers:

1

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.

+2  A: 

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.

Darin Dimitrov
Well, I hit an error where the .With method could not be found at this point .With<DefaultConventionScanner>();. Because I am very new to dependency injection, I did not know where to go from there. However it may be a case I do not know the namespace that function (or extension) resides in.
GONeale
I will take a look at the articles on the post you sent me, thanks. This does look interesting, DIInstanceProvider : IInstanceProvider.
GONeale
Perhaps I should move to Windsor after seeing Ayende's work @ http://www.castleproject.org/container/facilities/trunk/wcf/index.html
GONeale