当使用 ninject 约定绑定多个接口的所有实现时,我遇到了以下问题:
public interface IServiceA { }
public interface IServiceB { }
public class Service : IServiceA, IServiceB { }
public class FooA
{
public Foo(IEnumerable<IServiceA> a)
{
// a has 2 instances of Service
}
}
public class FooB
{
public Foo(IEnumerable<IServiceB> b)
{
// b has 2 instances of Service
}
}
// ...
kernel.Bind(x => x
.FromThisAssembly()
.SelectAllClasses().InheritedFrom<IServiceA>().
BindAllInterfaces());
kernel.Bind(x => x
.FromThisAssembly()
.SelectAllClasses().InheritedFrom<IServiceB>().
BindAllInterfaces());
var a = new FooA(kernel.GetAll<IServiceA>());
var b = new FooB(kernel.GetAll<IServiceB>());
我应该如何配置绑定以便只获得一个Service
ninjected 实例?