如何配置 Ninject 以注入 NodaTime IClock

How do I configure Ninject to inject the NodaTime IClock

在我的 NinjectConfigurator 中我有

container.Bind<IClock>().To<SystemClock>(); 

我也试过了

container.Bind<IClock>().To<SystemClock>().InSingletonScope();

但是我得到这个错误:

Error activating IClock using binding from IClock to SystemClock 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.

这是我的 class 注入,与我项目中使用 IoC 的所有其他工作 class 相同:

private readonly IDateTime _dateTime;
private readonly IClock _clock;

public SystemManager(IDateTime dateTime, IClock clock)
{
    this._dateTime = dateTime;
    this._clock = clock;
}

在这方面我找不到任何帮助。非常感谢任何帮助。

我自己有一段时间没用过NInject,但我相信你想用ToConstant()绑定到SystemClock的实例:

container.Bind<IClock>().ToConstant(SystemClock.Instance);