0

我正在按照在线教程学习 Castle.windsor。这是简单的示例代码:

public class Form1 {
    private readonly HttpServiceWatcher serviceWatcher;
    private System.ComponentModel.Container components = null;

public Form1()
{
    InitializeComponent();
}

public Form1(HttpServiceWatcher serviceWatcher) : this()
{
    this.serviceWatcher = serviceWatcher;
}
}

HttpServiceWatcher 在 xml 配置文件中。我的问题是:谁在调用具有参数的构造函数:public Form1(Http....)?在 program.cs 我有这个:

container.AddComponent("form.component",typeof(Form1));

Form1 form1 = (Form1) container["form.component"];

Application.Run(form1);
4

2 回答 2

1

容器在创建请求的对象时调用构造函数。被调用的构造函数是容器可以满足的具有最多参数的构造函数。

于 2009-01-22T18:39:07.300 回答
0

依赖容器本身创建对象(并因此调用构造函数)。

于 2009-01-21T07:28:43.097 回答