我有实现接口的类
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参数传递给构造函数?
提前谢谢!
答案 0 :(得分:2)
使用DependsOn
方法传递值。