我正在使用OWIN进行身份验证我想在AuthorisationServiceProvider中注入BusinessService我们如何实现它。
在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>();