我在我的项目中使用 EasyNetQ 库,我想使用 Ninject 作为 EasyNetQ 组件的 IoC 容器。
我创建了一个自定义记录器,以便从 EasyNetQ 记录任何内容:
public class LogNothingLogger : IEasyNetQLogger
{
...
}
然后在我的主要功能中使用 Ninject 扩展:
public class Program
{
static void Main(string[] args)
{
// Container creation and custom logger registration
IKernel cointainer = new StandardKernel();
cointainer.Bind<IEasyNetQLogger>().To<LogNothingLogger>();
// Register Ninject as IoC Container for EasyNetQ
cointainer.RegisterAsEasyNetQContainerFactory();
// Create bus
using (IBus bus = RabbitHutch.CreateBus("host=localhost"))
{
// Do something with bus...
}
}
}
但我得到以下异常:
Ninject.ActivationException was unhandled
More than one matching bindings are available.
Matching bindings:
1) binding from IEasyNetQLogger to LogNothingLogger
2) binding from IEasyNetQLogger to method
Activation path:
2) Injection of dependency IEasyNetQLogger into parameter logger of constructor of type RabbitBus
1) Request for RabbitBus
Suggestions:
1) Ensure that you have defined a binding for IEasyNetQLogger only once.
[...]
我以错误的方式使用这个包吗?有什么解决办法吗?
谢谢!