I feel like there is something obvious I’m missing here. I am trying to use ninject to create a class. The class accepts a single string parameter which is stored in Session of the HttpContext. How do I pass that parameter to this class?
The class looks like:
public class Manager : IManager
{
public Manager(string a) { ... }
}
I have a custom Dependency Resolver that looks like:
public class NinjectDependencyResolver : IDependencyResolver
{
IKernel kernel;
public NinjectDependencyResolver()
{
kernel = new StandardKernel();
Bind<IManager>().To<Manager>()
}
...
}
A typical controller looks like:
public class ManagerController : Controller
{
public ManagerController(IManager manager) { ... }
}
That the parameter is stored in the Session is relevant implementation detail and doesn’t belong into the Ninject configuration.
You should create a
IManagerConfigurationinterface that has a property for each config value for the manager and a Session Store implementation for that interface. Now you can add a simple binding for them and pass the interface to the managers constructor instead of the string.