我试图通过使用StructureMap为它提供接口,将ASP .Net MVC Session注入Controller。但是在注册表初始化时没有初始化尝试以HttpContext.Current
执行此操作时的StructureMap投诉。我相信我还有一条路可以找到。请指出我正确的方向。
以下是我的代码以获取更多信息:
DefaultRegistry.cs:
using System.Web;
using Company.O365Web.Infrastructure;
using StructureMap.Configuration.DSL;
using StructureMap.Graph;
namespace Company.O365Web.DependencyResolution
{
public class DefaultRegistry : Registry
{
#region Constructors and Destructors
public DefaultRegistry()
{
Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.With(new ControllerConvention());
});
For<ISessionState>()
.Singleton()
.Use(new SessionStateProvider(new HttpSessionStateWrapper(HttpContext.Current.Session)));
}
#endregion
}
}