如何在AuthorisationServiceProvider中注入businessservice

问题描述 投票:0回答:1

我正在使用OWIN进行身份验证我想在AuthorisationServiceProvider中注入BusinessService我们如何实现它。

authentication dependency-injection owin
1个回答
0
投票

在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文件中,配置您的resolcer,如下所示

container.RegisterType<IAuthenticationManager>(new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
container.RegisterType<IBusinessService, BusinessService>();
© www.soinside.com 2019 - 2024. All rights reserved.