3
我不能找出解决经由Autofac一种服务,用于在构造的Owin上下文,并且还设置在请求端以正确的方式。解决Autofac服务上Owin启动
由于OwinContext目前仍在建设中,因此无法通过致电HttpContext.Current.GetOwinContext().GetAutofacLifetimeScope()
找到LifetimeScope。 OwinContext尚未在此处提供。
在我的代码中,IAdfsAuthorizationProvider
服务直接在Container
上解析,但不会在请求后处理并且寿命更长。
我可以通过调用container.BeginLifetimeScope()
来创建一个新的LifeTimeScope,但现在生命期被分开了请求,并且可能会解析同一请求中的不同实例。而且我无法在正确的时间处理lifeTimeScope。
public void Configure(IAppBuilder app)
{
var builder = new ContainerBuilder();
builder.RegisterType<AdfsAuthorizationProvider>().As<IAdfsAuthorizationProvider>().InstancePerLifetimeScope();
var container = builder.Build();
app.UseAutofacMiddleware(container);
// **Service that's not binding to the request lifetime.**
var service = container.Resolve<IAdfsAuthorizationProvider>();
app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
{
Provider = new AuthorizationServerProvider(service),
});
}
有没有人有建议?