Ninject - 在嵌套绑定中绑定参数

Ninject - bind a parameter in a nested binding

有人可以告诉我如何修复以下代码创建的错误并将正确的值传递给 "B" 的构造函数中的 "x" 参数吗?

我得到:附加信息:激活字符串时出错

    interface IA { }

    class A : IA
    {
        public A(IB b) { }
    }

    interface IB { }

    class B : IB
    {
        public B(string x) { }
    }

    class Main() {
        IKernel n = new StandardKernel();
        n.Bind<IA>().To<A>();
        n.Bind<IB>().To<B>();
        IA a = n.Get<IA>(new ConstructorArgument("x", "BLE"));
    }

你试过了吗

IA a = n.Get<IA>(new ConstructorArgument("x", "BLE", true));

(真标志 => 继承)?

您可以继承 ConstructorArgument(如果不是继承,它仅适用于直接解析的类型 - 在本例中为 A),或者您可以调整 B 的绑定并添加一个参数 (ConstructorArgument) 到它。