我有一个界面:
public interface IService
{
void DoStuff(int parm1, string parm2, Guid gimmeABreakItsAnExampleK);
}
我想配置 Ninject (v3) 绑定,以便我可以有一个“调度程序” shuffle 方法调用多个实例IService
,如下所示:
public sealed class DispatcherService : IService
{
private IEnumerable<IService> _children;
public DispatcherService(IEnumerable<IService> children)
{
this._children = children.ToList();
}
public void DoStuff(int parm1, string parm2, Guid gimmeABreakItsAnExampleK)
{
foreach(var child in this._children)
{
child.DoStuff(parm1, parm2, gimmeABreakItsAnExampleK);
}
}
}
然而,我的绑定,看起来像这样,最终在运行时抛出一个异常,指示循环依赖:
this.Bind<IService>().To<DispatcherService>();
this.Bind<IService>().To<SomeOtherService>()
.WhenInjectedExactlyInto<DispatcherService>();
this.Bind<IService>().To<YetAnotherService>()
.WhenInjectedExactlyInto<DispatcherService>();
这可能吗?如果是这样,我做错了什么?忍者能否逃脱这种周期性依赖的厄运?