Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您可以通过结构映射将会话引用注入您的类吗
是的。
如果您指的是当前用户的 HTTP 会话,请尝试将其添加到您的容器注册代码中:
For<HttpSessionStateBase>().TheDefault.Is.ConstructedBy(() => new HttpSessionStateWrapper(HttpContext.Current.Session));
现在,任何通过 StructureMap 检索到的将 HttpSessionStateBase 作为其构造函数参数之一的类都应该获取当前会话。