In my NinjectConfigurator I have
container.Bind<IClock>().To<SystemClock>();
I have also tried
container.Bind<IClock>().To<SystemClock>().InSingletonScope();
But I get this error:
Error activating
IClock
using binding fromIClock
toSystemClock
No constructor was available to create an instance of the implementation type.Activation path: 3) Injection of dependency IClock into parameter clock of constructor of type SystemManager 2) Injection of dependency ISystemManager into parameter systemManager of constructor of type AccountController 1) Request for AccountController
Suggestions: 1) Ensure that the implementation type has a public constructor. 2) If you have implemented the Singleton pattern, use a binding with InSingletonScope() instead.
This is my class with the injection, same as all other working classes with IoC in my project:
private readonly IDateTime _dateTime;
private readonly IClock _clock;
public SystemManager(IDateTime dateTime, IClock clock)
{
this._dateTime = dateTime;
this._clock = clock;
}
I couldn't find anything to help me on this. Any help is much appreciated.
I haven't used NInject myself for a while, but I believe you want to use ToConstant()
to bind to the instance of SystemClock
:
container.Bind<IClock>().ToConstant(SystemClock.Instance);
See more on this question at Stackoverflow