Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 5 如何在StructureMap中映射IAAuthenticationManager实现_Asp.net Mvc 5_Structuremap_Asp.net Identity - Fatal编程技术网

Asp.net mvc 5 如何在StructureMap中映射IAAuthenticationManager实现

Asp.net mvc 5 如何在StructureMap中映射IAAuthenticationManager实现,asp.net-mvc-5,structuremap,asp.net-identity,Asp.net Mvc 5,Structuremap,Asp.net Identity,我很难同时使用StructureMap和Microsoft AspNet Identity,因为我似乎不知道如何映射IAAuthenticationManager的实现。我正试图按照下面的示例在DefaultRegistry中显式地映射它 public class DefaultRegistry : Registry { public DefaultRegistry() { Scan( scan => {

我很难同时使用StructureMap和Microsoft AspNet Identity,因为我似乎不知道如何映射IAAuthenticationManager的实现。我正试图按照下面的示例在DefaultRegistry中显式地映射它

   public class DefaultRegistry : Registry {

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

            For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication);
        }
   }
public类DefaultRegistry:Registry{
公共注册处(){
扫描(
扫描=>{
扫描。卡入总成();
scan.WithDefaultConventions();
使用(新的ControllerConvention())扫描;
});
For()。使用(()=>HttpContext.Current.GetOwinContext().Authentication);
}
}

主要的问题是HttpContext.Current始终为null,但我甚至不确定即使它不为null,它是否能工作。我是一个拥有StructureMap和AspNet身份的大新手,所以在这里做任何愚蠢的事情,请随时给我打电话。谢谢你的帮助

这本身并不是一个真正的结构图问题。HttpContext.Current仅在ASP.Net中的HTTP请求内部可用。如果要在StructureMap中使用HttpContext,我建议您要么优雅地检查空值,要么尝试切换到使用HttpContextWrapper/HttpContextBase抽象,这样您就可以在ASP.Net之外的测试中运行该代码。

好吧,上面的代码似乎工作得很好,我不确定为什么以前它似乎不工作。我不知道解决这个问题的协议是什么,但我不想让任何人认为他们不能参考上面的内容,因为它是有效的