【发布时间】:2018-09-02 21:49:22
【问题描述】:
我正在使用 OWIN 进行身份验证,我想在 AuthorisationServiceProvider 中注入 BusinessService 我们如何实现它。
【问题讨论】:
标签: authentication dependency-injection owin
我正在使用 OWIN 进行身份验证,我想在 AuthorisationServiceProvider 中注入 BusinessService 我们如何实现它。
【问题讨论】:
标签: authentication dependency-injection owin
在您的 Startup.Auth.cs 文件中,附加您的 ApplicationUserManager,如下所示
app.CreatePerOwinContext(() => DependencyResolver.Current.GetService<ApplicationUserManager>());
并在您的 ApplicationUserManager 中使用依赖注入来注入您的业务服务,如下所示
private readonly IBusinessService _businessService;
public ApplicationUserManager(IdentityRepository store, IBusinessService businessService) : base(store)
{
_businessService = businessService;
}
最后,在您的 DependencyRegistrar.cs 文件中,如下配置您的解析器
container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
container.RegisterType<IBusinessService, BusinessService>();