This project is read-only.

object Scope per request when getting object via IOC container

Topics: Web Api
Jan 5, 2012 at 10:44 PM

Hi Guys,

How to set up Scope of object per request in Web Api P6 when retrieving object from IOC container(Ninject).

The HttpContext.Current as well as OperationContext.Current is null when I tried to retrieve my serviceDiagnostic object in my CustomFormatter class.  It used to work in P5 as below:

In Web Api P5,

When the client pass in debug=true in Uri as Query parameter , my RequestHandler process the incoming request and set the ServiceDiagnostic object to Enabled.

Ninject binding:

Bind<IServiceDiagnostics>().To<WcfServiceDiagnostics>().InScope(c => HttpContext.Current);

and in my customFormatter class usage was:

public class CustomFormatter : MediaTypeFormatter

  protected override void OnWriteToStream(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
var isDebugEnabled  = Resolver.Get<IServiceDiagnostics>().Enabled;


Am I missing something here ?? or is there any alternative way to achieve this or its a bug in the Ninject or Api 6??