title: C# Winforms MVP-Passive View, where to handle the Model?
body: <p>I am new to the MVP-PV type of pattern and have some questions on how to handle the Models. (I am using simple CRUD statements in the app, not EF) Does the Model contain the CRUD that is used to retrieve data or just contain the properties for the model. Where do you instantiate the Model? In the View passed with the Presenter? At the top of the Presenter? In each method?</p>
  
  <p>Here is a simple example of what I am doing with MVP.</p>
  
  <p>The UserControl is added like this:</p>
  
  <pre><code>ElementView uControl = new ElementView()
  uControl.Location = new Point(0, 0);
  uControl.Dock = DockStyle.Fill;
  rPanel.Controls.Add(uControl);
  </code></pre>
  
  <p>The Interface:</p>
  
  <pre><code>namespace MPVExample.View
  {
      public interface IElementView
      {
          int IElementPKey { get; set; }
          string INumber { get; set; }
          string IDescription { get; set; }
  
          event EventHandler&lt;EventArgs&gt; OnEditElement;
      }
  }
  </code></pre>
  
  <p>The View:</p>
  
  <pre><code>namespace MPVExample.View
  {
      public partial class ElementView : UserControl, IElementView
      {
          private ElementPresenter presenter = null;
  
          public event EventHandler&lt;EventArgs&gt; OnEditElement;
  
          public int IElementPKey 
          {
              get { return TxtElementKey.Text; }
              set { TxtElementKey.Text = value; }
          }
  
          public string INumber
          {
              get { return TxtNumber.Text; }
              set { TxtNumber.Text = value; }
          }
  
          public string IDescription
          {
              get { return TxtDescription.Text; }
              set { TxtDescription.Text = value; }
          }
  
          public ElementView ()
          {
              presenter = new ElementPresenter(this);
              InitializeComponent();
          }
  
          private void BtnEdit_Click(object sender, EventArgs e)
          {
              OnEditElement?.Invoke(this, EventArgs.Empty);
          }
      }
  }
  </code></pre>
  
  <p>The Presenter:</p>
  
  <pre><code>namespace MPVExample.Presenter
  {
      public class ElementPresenter
      {
          private readonly IElementViewView;
          //ElementModel Model = new ElementModel (); //Instantiate Here?
  
          public ElementPresenter(IElementView view)
          {
              try
              {
                  if (view != null)
                  {
                      View = view;
                      Initialize();
                  }
                  else
                  {
                      throw new ArgumentNullException("IElementView");
                  }
              }
              catch (Exception ex)
              {
                   //Log Error
              }
          }
  
          private void Initialize()
          {
              try
              {
                  View.OnEditElement += Edit_Element;
              }
              catch (Exception ex)
              {
                   //Log Error
              }
          }
  
          private void Edit_Element(object sender, EventArgs e)
          {
              try
              {
               ElementModel model = new ElementModel(); //Instantiate Here?
               Model.ElementPKey = View.IElementPKey;
               Model.Number = Convert.ToByte(View.INumber);
               Model.Description = View.IDescription;
               Model.Edit();
              }
              catch (Exception ex)
              {
                   //Log Error
              }
          }
      }
  }
  </code></pre>
  
  <p>The Model:</p>
  
  <pre><code>namespace MPVExample.Models
  {
      public class ElementModel 
      {
          public int ElementPKey { get; set; }
          public byte Number { get; set; }
          public string Description { get; set; }
  
          public void Edit() //Does this belong in here?
          {
               //SQL to Edit record
          }
  
          public void Save() //Does this belong in here?
          {
               //SQL to Save record
          }
  
          public void Get() //Does this belong in here?
          {
               //SQL to Get record
          }
  
          public void Delete() //Does this belong in here?
          {
               //SQL to Delete record
          }
      }
  }
  </code></pre>