使用OWIN进行依赖注入

时间:2017-10-24 04:16:28

标签: c# asp.net asp.net-web-api owin unity-container

我使用Unity DI + OWIN + ASP.NET WebAPI并希望连接Unity和OWIN,否则SecurityStampValidator之类的东西不起作用。

在Startup.Auth.cs中我有:

app.CreatePerOwinContext(() =>
    UnityConfig.GetConfiguredContainer().Resolve<ApplicationUserManager>());

然而,这似乎是错误的,因为给定hereIDependencyResolver的默认实现为每个请求创建了一个子容器/范围,而上面的代码看起来像是在父进程中解析容器

如何获取当前范围或子容器?

这里返回null

app.CreatePerOwinContext(() => 
    (ApplicationUserManager)DependencyResolver.Current.GetService(typeof(ApplicationUserManager)));

0 个答案:

没有答案