R – who calls the constructor witth parameter (Castle.Windsor)

castle-windsor

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

Best Answer

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.

Related Topic