title: How to Form.ShowDialog() using MVP and Passive Views?
body: <p><strong>Summary</strong></p>
  
  <p>I'm experimenting with the MVP pattern in a Windows Forms application.</p>
  
  <p>I'd like to make both my Presenters and Views platform agnostic, so if I wish to port my application to another platform, say the Web or mobile, I simply need to implement the views with platform dependant GUI, and my presenters can still be platform independent.</p>
  
  <p>And now I wonder, <strong>how to ShowDialog() using MVP and Passive Views?</strong></p>
  
  <p>To my understanding so far, passive views shouldn't know/care about any presenter. They don't even know it exists. So, the solution presented in this question's answer is not suitable, according to me: 
  <a href="https://stackoverflow.com/questions/3437566/refactoring-form-showdialog-code-to-mvp">Refactoring Form.ShowDialog() code to MVP</a></p>
  
  <p>Some code samples to help on the understanding:</p>
  
  <p><strong><code>ApplicationView</code></strong></p>
  
  <pre><code>public partial class ApplicationForm : Form, IApplicationView {
      // I ensure that all the IApplicationView events are raised 
      // upon button clicks text changed, etc.
      // The presenter, which this view ignores the existence, 
      // is subscribed to the events this view raises.
  }
  </code></pre>
  
  <p><strong><code>ApplicationPresenter</code></strong></p>
  
  <pre><code>public class ApplicationPresenter 
      : Presenter&lt;IApplicationView&gt;
      , IApplicationPresenter {
      public ApplicationPresenter(IApplicationView view) : base(view) {
          View.OnViewShown += OnViewShown;
      }
  
      public void OnViewShown() {
          IAuthenticaitonView authView = new AuthenticationForm();
          IAuthenticationPresenter authPresenter = new AuthenticationPresenter(authView);
          authPresenter.ShowDialog(); // 1.                       
      }
  }
  </code></pre>
  
  <ol>
  <li><em>This is where I'm struggling. The ApplicationPresenter is like the master in the universer and may be aware of the user authentication through both the <code>IAuthenticationView</code> and <code>IAuthenticationPresenter</code></em>.</li>
  </ol>
  
  <p><strong><code>IAuthenticationView</code></strong></p>
  
  <pre><code>public interface IAuthenticationView : IDialogView {
      string ErrorMessage { get; set; }
      string Instance { get; set; }
      IEnumerable&lt;string&gt; Instances { get; set; }
      string Login { get; set; }
      string Password {get; set; }
  
      void EnableConnectButton(bool enabled);
  
     event VoidEventHandler OnConnect;
     event SelectionChangedEventHandler OnDatabaseInstanceChanged;
     event VoidEventHandler OnLoginChanged;
     event VoidEventHandler OnPasswordChanged;
  }
  </code></pre>
  
  <p><strong><code>IDialogView</code></strong></p>
  
  <pre><code>public interface IDialogView : IView {
      void ShowDialog();
  }
  </code></pre>
  
  <p><strong><code>IView</code></strong></p>
  
  <pre><code>public interface IView { 
      void Show();
  
      event VoidEventHandler OnViewInitialize;
      event VoidEventHandler OnViewLoad;
      event VoidEventHandler OnViewShown;
  }
  </code></pre>
  
  <p><strong><code>IAuthenticationPresenter</code></strong></p>
  
  <pre><code>public interface IAuthenticationPresenter : IPresenter&lt;IAuthenticationView&gt; {
      void OnConnect();
      void OnViewDatabaseInstanceChanged(SelectionChangedEventArgs e);
      void OnViewLoginChanged();
      void OnViewPasswordChanged();
  }
  </code></pre>
  
  <p><strong><code>IPresenter&lt;V&gt;</code></strong></p>
  
  <pre><code>public interface IPresenter&lt;V&gt; where V : IView {
      V View { get; }
  
      OnViewInitialize();
      OnViewLoad();
      ShowView();
  }
  </code></pre>