Lightweight WinForms MVP framework designed to provide separation guidance and testability but mostly get out of your way.
Create marker interface for your view:
public interface ISampleDialogView : IDialog
{
}
Create SimpleDialogPresenter
inheriting from DialogPresenter
and a marker interface:
public class SampleDialogPresenter : DialogPresenter<ISampleDialogView>, IPresentSampleDialog
{
public SampleDialogPresenter(Func<ISampleDialogView> viewFactory)
: base(viewFactory)
{
}
}
public interface IPresentSampleDialog : IPresentDialog
{
}
DialogPresenter<ISimpleDialogView>
. By doing this we get ISimpleDialogView
included for free in the View
base class variable.Create SimpleDialog
as a new form in your project:
public partial class SampleDialog : Dialog<IPresentSampleDialog>, ISampleDialogView
{
public SampleDialog()
{
InitializeComponent();
}
}
Dialog<IPresentSampleDialog>
gets us our presenter for free as the base class variable Presenter
inside the view. This allows us to do more complex view->presenter interaction, for example:
private void tsShowDialog_Click(object sender, EventArgs e)
{
Presenter.ShowDialogSample();
}
Seen here.
That's it. You're ready to go.
Create a dummy non-generic class to appease the designer.
public partial class MainForm : MainFormDesignable { }
//This gives the WinForms designer a default constructor which allows it to load the form
public class MainFormDesignable : View<IPresentMainForm> {}
Seen here