【问题标题】:how to inject businessservice in AuthorisationServiceProvider如何在 AuthorisationServiceProvider 中注入业务服务
【发布时间】:2018-09-02 21:49:22
【问题描述】:

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

【问题讨论】:

    标签: authentication dependency-injection owin


    【解决方案1】:

    在您的 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>();
    
    猜你喜欢
    • 2016-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    相关资源
    最近更新 更多