我使用Unity DI + OWIN + ASP.NET WebAPI并希望连接Unity和OWIN,否则SecurityStampValidator
之类的东西不起作用。
在Startup.Auth.cs中我有:
app.CreatePerOwinContext(() =>
UnityConfig.GetConfiguredContainer().Resolve<ApplicationUserManager>());
然而,这似乎是错误的,因为给定here的IDependencyResolver
的默认实现为每个请求创建了一个子容器/范围,而上面的代码看起来像是在父进程中解析容器
如何获取当前范围或子容器?
这里返回null
:
app.CreatePerOwinContext(() =>
(ApplicationUserManager)DependencyResolver.Current.GetService(typeof(ApplicationUserManager)));