为 autofac 中间件使用流水线阶段标记

Use pipeline stage marker for autofac middleware

我在 autofac

中注册了一个 per-request 生命周期中间件(它有一些依赖)
builder.RegisterType<RequestLocaleSetter>().InstancePerRequest();

然后我在startup.cs

注册了所有的autofac中间件
        app.UseAutofacMiddleware(resolver.ApplicationContainer);
        app.UseAutofacMvc();

我可以为在 startup.cs 中注册的中间件设置管道阶段,例如

        app.Use(typeof(RequestLocaleSetter));
        app.UseStageMarker(PipelineStage.PostAcquireState);

某个autofac注册的中间件怎么办?

来自 autofac 文档: http://docs.autofac.org/en/latest/integration/owin.html#controlling-middleware-order

If you want more control over when DI-enabled middleware is added to the pipeline, you can use the UseAutofacLifetimeScopeInjector and UseMiddlewareFromContainer extensions.

 var builder = new ContainerBuilder();
 builder.RegisterType<MyCustomMiddleware>(); //... var container =
 builder.Build();

 // This adds ONLY the Autofac lifetime scope to the pipeline.
 app.UseAutofacLifetimeScopeInjector(container);

 // Now you can add middleware from the container into the pipeline //
 wherever you like. For example, this adds custom DI-enabled middleware
 // AFTER the Web API middleware/handling. app.UseWebApi(config);
 app.UseMiddlewareFromContainer<MyCustomMiddleware>();