derfsplat / MiniMVP

Lightweight WinForms MVP framework designed to provide separation guidance and testability but mostly get out of your way.
MIT License
20 stars 9 forks source link

MiniMVP

Lightweight WinForms MVP framework designed to provide separation guidance and testability but mostly get out of your way.

Example - Simple Dialog

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
    {
    }

Create SimpleDialog as a new form in your project:

    public partial class SampleDialog : Dialog<IPresentSampleDialog>, ISampleDialogView
    {
        public SampleDialog()
        {
            InitializeComponent();
        }
    }

That's it. You're ready to go.

Designer Support When Inheriting Generic View Classes

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