Hi,
I am using StructureMap 3, on a webapi project with the package structuremap.webapi2.
As far as I understand the lifetime scope of the nested container is based on the Http request, which is great, but this scope is build upon on an IHttpModule which is not consistant with the new OWIN pipeline architecture, could we do something like this :
StructureMapOWINMiddleware in remplacement of the IHttpModule :
//basic draft
public class StructureMapOWINMiddleware : OwinMiddleware
{
public StructureMapOWINMiddleware(OwinMiddleware next)
: base(next)
{
}
public async override Task Invoke(IOwinContext context)
{
IoC.DependencyScope.CreateNestedContainer(); // I moved de dependencyScope static in the IOC Class
await Next.Invoke(context); // Process the request with all other OWIN Middleware
HttpContextLifecycle.DisposeAndClearAll(); //clean all
IoC.DependencyScope.DisposeNestedContainer();
}
}
and in the startup class, on the first line to be sure the IOC is configured before everthing else :
IContainer container = IoC.Initialize();
app.Use(typeof(StructureMapOWINMiddleware));
Please let me know what do you think
Cheers
Axel