首页新闻招聘找找看知识库
  • 回复:2 浏览:2031 2016-08-17 23:57 来自 越天
    public void ConfigureServices(IServiceCollection services)
            {
               
                services.AddEntityFrameworkSqlServer().AddDbContext<BaseDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
                
                services.AddMemoryCache();
    
                services.DependMapping();
                services.AddSession();
                services.AddApplicationInsightsTelemetry(Configuration);
                //services.DependMapping();    1111
                services.AddMvc();
    
            }
     public static void DependMapping(this IServiceCollection services)
            {
                services.AddTransient<IHttpContextAccessor, HttpContextAccessor>();
    }

     

    请问下,为什么注入DependMapping放在AddSession的后面,IHttpContextAccessor注入的httpcontext值为null?
  • Savorboard
    2016-08-23 09:11 Savorboard
    session 中要依赖 IHttpContextAccessor,所以要先注入
    第1楼 回到顶楼
  • 越天
    2016-08-23 09:31 越天
    @Savorboard
    原来是这样呀 Thanks
    第2楼 回到顶楼
登录后才能评论,请先登录注册