1
votes

I am confused with the proper implementation of Castle Windsor for Winforms scenarios, all the doc I had found is about WCF and ASP.NET MVC so I ask for help to do the proper implementation of Castle Windsor in Windows Forms. Now here is my code... I begin with this approach of MVP http://dotnetchris.wordpress.com/2009/02/16/creating-a-generic-model-view-presenter-framework/

pasing to Winforms I made this

public interface IPresenter<TViewModel>
{
    TViewModel View { get; set; }

    event EventHandler ViewInitialized;

    void OnViewInitialized(EventArgs e);

    event EventHandler ViewLoaded;

    void OnViewLoaded(EventArgs e);
}

and the base Form is

public partial class MvpForm<TPresenter, TViewModel> : Form
    where TPresenter : IPresenter<TViewModel>
    where TViewModel : class

following the first part my presenter is

public class PatientSearchCreatePresenter: IPresenter<IPatientFilterViewModel>
{
    IPatientBusinessService patient;

    /// <summary>
    /// Initializes a new instance of the <see cref="PatientFilterPresenter" /> class.
    /// </summary>
    public PatientSearchCreatePresenter(IPatientBusinessService Patient)
    {
        patient = Patient;
    }

and My Form to search and Create patients is something like this

public partial class FormSearchCreatePatient : MvpForm<PatientSearchCreatePresenter,IPatientSearchCreateViewModel> , IPatientSearchCreateViewModel
{

Where and How should I perform the Installation & Registration of the Castle Component for the View, and the presenter service property

thank you so much

1
Thank you I follow the same approach and work itKmilo

1 Answers

1
votes

Here's is how i did it sometime ago:

public class BusinessContainer : WindsorContainer
{
    public BusinessContainer()
    {
        RegisterComponents();
    }

    private void RegisterComponents()
    {
        // Presenters
        AddComponentWithLifestyle("HelloWorld.presenter", typeof(HelloWorldPresenter), LifestyleType.Transient);
    }
}
}

Since the inclusion of the IoC container is a little bit complex, for the complete step by step, take a look here.