who calls the constructor witth parameter (Castle.Windsor)

别等时光非礼了梦想. 提交于 2019-12-24 21:03:06

问题


I am learning castle.windsor following the tutorial online. this is the simple sample code:

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 is in the xml conf file. My question is: who is calling the constructor that has the parameter: public Form1(Http....) ? at the program.cs i have this:

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

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

Application.Run(form1);

回答1:


The container calls the constructor when it creates the requested object. The constructor that gets called is the constructor with the most arguments that the container can satisfy.




回答2:


The dependency container itself creates the object (and thus calls the constructor).



来源:https://stackoverflow.com/questions/464299/who-calls-the-constructor-witth-parameter-castle-windsor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!