views:

35

answers:

1

So I already have a working implementation of StructureMap with the WCF service (including custom instance provider, behaviors, etc.)

When I try to have an object that is instantiated only once per user request, I use the InstanceScope.HttpContext and it throws because the context is null.

Do anyone have a proper way of doing that?

+1  A: 

On the server-side of the WCF service? By default, WCF has nothing to do with ASP.NET and thus all your HttpContext etc. aren't there.

By default, your WCF services will be called on a "per-call" basis, e.g. each request gets a brand-new, separate, totally isolated instance of your service class. Why not just put those things into the service class as internal fields??

Or you might want to check out this blog post on how to abstract request state and providing sample implementations for ASP.NET (using HttpContext.Items) and WCF.

marc_s
I was actually thinking about it this morning while walking to work. The Service Host would be the best place to store it. I'll see what can be done.
Maxim
@Maxim: yes, the service host might be another place to hook things into. Be aware that the host exists only once for all concurrently existing service class instances, though! It's shared among all service instances - which might be a good or a bad feature, depending on what you want to achieve.
marc_s