gpt4 book ai didi

asp.net-mvc-5 - 如何获取在 StructureMap 中映射的 IAuthenticationManager 实现

转载 作者:行者123 更新时间:2023-12-02 04:52:47 25 4
gpt4 key购买 nike

我很难同时使用 StructureMap 和 Microsoft AspNet Identity,因为我似乎无法弄清楚如何映射 IAuthenticationManager 的实现。我试图根据下面的示例在 DefaultRegistry 中明确映射它。

   public class DefaultRegistry : Registry {

public DefaultRegistry() {
Scan(
scan => {
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});

For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);
}
}

主要问题是 HttpContext.Current 始终为空,但我什至不确定这是否有效,即使它不为空。我是 StructureMap 和 AspNet Identity 的大新手,所以如果我在这里做任何愚蠢的事情,请随时调用我。感谢您的帮助!

最佳答案

这本身并不是真正的 StructureMap 问题。 HttpContext.Current 仅在 ASP.Net 的 HTTP 请求中可用。如果您想在 StructureMap 中使用 HttpContext,我建议您要么确保优雅地检查 null,要么尝试切换到使用 HttpContextWrapper/HttpContextBase 抽象,以便您可以在测试中在 ASP.Net 之外运行该代码。

关于asp.net-mvc-5 - 如何获取在 StructureMap 中映射的 IAuthenticationManager 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26304464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com