Session null in ASP.Net MVC Controller Constructors

前端 未结 6 1700
北海茫月
北海茫月 2020-11-27 13:27

Why is Session null in the constructors of Controllers? It can be accessed from Action methods. Presumably, because the MVC Routing framework is responsible for newing-up a

6条回答
  •  北海茫月
    2020-11-27 13:51

    The Session is injected later in the life-cycle. Why do you need the session in the constructor anyway? If you need it for TDD you should wrap the session into a mockable object.

提交回复
热议问题