I have an IFoo
instance which I need to use as per request instance. Here is how my startup class look like:
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
config.Routes.MapHttpRoute("DefaultHttpRoute", "api/{controller}");
app.Use<RandomTextMiddleware>()
.UseWebApi(config);
}
RandomTextMiddleware
is a pass-through middleware and I need an instance of IFoo
implementation there. I also need an instance of IFoo
implementation inside my Web API pipeline.
How would you solve this problem so that I have the same instance of IFoo
implementation inside the RandomTextMiddleware
and the Web API pipeline per HTTP request?
@darrelmiller
Why should that effect the state? Assume that
RandomTextMiddleware
is my caching middleware and inside that middleware I need to go to my ETagStore (redis, mongodb, etc.) to check the ETag. Shouldn't I have a way of resolving that dependency? Should my middleware have a deep knowladge of creating that store instance? I don't think so.