我有以下课程:
using System;
interface IA { }
class A1 : IA { }
class A2 : IA { }
class B
{
public B(IA a) {}
}
class BProvider : Provider<B>
{
IA _a;
public BProvider(IA a) { _a=a; }
protected override B CreateInstance(IContext context) { return new B(_a); }
}
ninject 模块 Load() 代码:
Bind<IA>().To<A1>();
Bind<IA>().To<A2>();
Bind<B>().ToProvider<BProvider>();
主要代码:
kernel.GetAll<IA>(); // works fine
kernel.GetAll<B>(); // I expect to get IEnumerable<B> with two elements, but instead of this I get an error that there are multiple bindings of IA and ninject cannot determine which to use
所以问题是我是否可以使最后一个语句按预期工作或以其他方式进行?