I am trying to inject ASP .Net MVC Session into a Controller by providing in interface for it using StructureMap. But StructureMap complaints while trying to do this as HttpContext.Current
is not initialized at the time of registry initialization. I am sure there is a way around it I have yet to find. Please point me into the right direction.
Here is my code for more information:
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
}
}