2011-04-15 49 views
0

我有類實現該接口城堡溫莎 - 不刺默認構造函數參數

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>(); 

的問題是接口Eq功能不能通過Address。有沒有辦法使用CastleWindsor將非字符串參數傳遞給構造函數?
在此先感謝!

+0

你有什麼錯誤? – mathieu 2011-04-15 09:48:46

+0

我無法編譯它。 – StuffHappens 2011-04-15 10:40:43

回答

2

使用DependsOn方法來傳遞值。

+0

這就是我正在尋找的。謝謝! – StuffHappens 2011-04-15 10:40:21

+0

@Krzysztof ..它沒有在我的程序中工作..它給編譯錯誤 「不能從'windsorPoly.Square'轉換爲'字符串'」 – 2013-02-05 08:47:28