views:

80

answers:

1

Hi, I am having this problem. I have integrated structuremap with wcf like it is described here: http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/07/29/integrating-structuremap-with-wcf.aspx

the problem is that I am having classes which have constructor parameters like userId and applicationId that I must pass in order structuremap can create them.

How to do this? How can i pass these parameters on each wcf call?

+1  A: 

When you create your instance provider, get those parameters out of your message during the call to GetInstance:

public object GetInstance(InstanceContext instanceContext, Message message)
{
   YourDataContract data = message.GetBody<YourDataContract()>;
   string userID = data.userID;
   string applicationID = data.appID;

   //now go ahead and use structuremap....
}

This assumes your Message body is a defined data contract type (in my example, it's a type named 'YourDataContract').

David Hoerster
Good!I am doing structuremap initialization in Global.asax where I initialize sm registers.What I have in GetInstance is this: return ObjectFactory.GetInstance(_serviceType);So my questions are:1. my service depends on a command class which needs the above params, but the configuration of sm is not done in the GetInstance. How to configure this scenario?2. I suppose that for inserting the above params into message body I must create MessageInspector on the Client Side. Is this true?thanks
Luka