UserNamePasswordValidator:当 DI 和框架发生冲突时

编程入门 行业动态 更新时间:2024-10-28 16:27:08
本文介绍了UserNamePasswordValidator:当 DI 和框架发生冲突时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为 WCF 服务构建自定义 UserNamePasswordValidator.我正在将服务与 Autofac + WCF/多租户连接起来,所有这些都很好地结合在一起.但是我不确定使用什么策略来连接/实现这个身份验证类.

I am building a custom UserNamePasswordValidator for a WCF service. I am wiring up the service with Autofac + WCF/multitenant, all fitting neatly together. However I'm not sure what strategy to use to wire/implement this authentication class.

理想情况下,我会从

public class MyValidator : UserNamePasswordValidator { public MyValidator(Func<Owned<IMyUserService>> userservicefactory) { ... } }

然而,这并不是完全可能的,因为 WCF 使用 UserNamePasswordValidator 的方式(唯一的选择似乎是无参数构造函数).

However, this isn't strictly possible because of the way that a UserNamePasswordValidator is consumed by WCF (the only option appears to be parameterless constructor).

所以,问题:

  • 我是否正确或者是否有一些 WCF 配置巫术可以用来配置 UserNamePasswordValidator factory?
  • 如果否",那么在这种情况下可以使用的最DI 正确"的回退策略是什么?
  • 推荐答案

    我在启动时或在自定义 ServiceHostFactory 中的代码中配置了服务主机.

    I configured the service host in code at startup or within a custom ServiceHostFactory.

    从 XML 配置中,我删除了

    From the XML configuration, I removed

    <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Common.MyCustomUsernamePasswordValidator, Common"/ -->

    而且由于我在托管之前配置了我的容器:

    And since I configured my container prior to hosting:

    var auth = host.Credentials.UserNameAuthentication; auth.UserNamePasswordValidationMode = UserNamePasswordValidationMode.Custom; auth.CustomUserNamePasswordValidator = container.Resolve<Common.MyCustomUsernamePasswordValidator>();

    更多推荐

    UserNamePasswordValidator:当 DI 和框架发生冲突时

    本文发布于:2023-10-22 09:25:28,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1517115.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:发生冲突   框架   UserNamePasswordValidator   DI

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!