Castle Windsor - 不是sting默认构造函数参数

时间:2011-04-15 08:58:21

标签: c# castle-windsor

我有实现接口的类

public class Address
{
    public string City { get; set; }
    public string Street { get; set; }
}
public class MyComponent : IMyComponent
{
    public MyComponent(Address address)
    {
        this.Value = address;
    }

    public Address Value { get; private set; }
}

public interface IMyComponent
{
    Address Value { get; }
}

我希望能够像使用CastleWindsor一样将它绑定到接口

        IWindsorContainer container = new WindsorContainer();

                    container.Register(
                        Component.For<IMyComponent>()
                        .ImplementedBy<MyComponent>()
                        .Parameters(Parameter.ForKey("address")
                            .Eq(new Address {City = "New York", Street = "street"})));
    var component = container.Resolve<IMyComponent>();

问题是我无法将Address传递给Eq函数。有没有办法使用CastleWindsor将not-string参数传递给构造函数?
提前谢谢!

1 个答案:

答案 0 :(得分:2)

使用DependsOn方法传递值。