Castle windsor Castle Windsor属性注入不适用于动态参数

Castle windsor Castle Windsor属性注入不适用于动态参数,castle-windsor,nservicebus,Castle Windsor,Nservicebus,我们希望使用NserviceBus Saga,为了做到这一点,您需要为您的Saga使用无参数构造函数。注入关注点的唯一其他方法是使用似乎不起作用的属性注入。任何帮助和指导都将不胜感激 我已经在下面发布了示例代码,显示了问题所在 class Program { static void Main(string[] args) { var container = new WindsorContainer(); container.Register(Co

我们希望使用NserviceBus Saga,为了做到这一点,您需要为您的Saga使用无参数构造函数。注入关注点的唯一其他方法是使用似乎不起作用的属性注入。任何帮助和指导都将不胜感激

我已经在下面发布了示例代码,显示了问题所在

class Program
{
    static void Main(string[] args)
    {
        var container = new WindsorContainer();

        container.Register(Component.For<ClassWithDynamicProperty>()
            .DynamicParameters((r, k) =>{ k["testString"] = "test"; }) );

        container.Register(
            Component.For<TestClassWithPropertyInjection>());

        container.Register(
            Component.For<TestClassWithConstructorInjection>());

        var class1 = container.Resolve<TestClassWithConstructorInjection>();
        var class2 = container.Resolve<TestClassWithPropertyInjection>();

        Debug.Assert(class1.DynamicClass == null);
        Debug.Assert(class2.ClassWithDynamicProperty == null);

    }
}

internal class TestClassWithPropertyInjection
{
    public TestClassWithPropertyInjection()
    {

    }

    public ClassWithDynamicProperty ClassWithDynamicProperty { get; set; }
}

internal class TestClassWithConstructorInjection
{
    private readonly ClassWithDynamicProperty _classWithDynamicProperty;

    public TestClassWithConstructorInjection(ClassWithDynamicProperty classWithDynamicProperty)
    {
        _classWithDynamicProperty = classWithDynamicProperty;
    }

    public ClassWithDynamicProperty DynamicClass { get { return _classWithDynamicProperty; }  }

}

public class ClassWithDynamicProperty
{
    public string TestString { get; private set; }

    public ClassWithDynamicProperty(string testString)
    {
        TestString = testString;
    }
}

在v5中,您不再需要在Sagas中使用默认的ctor,您只需执行ctor InjectionAsome,谢谢。我会看一看,让你知道它是否有效。