Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8739265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:54:01+00:00 2026-06-13T10:54:01+00:00

Have been learning about MVP and have tried writing a test app using it

  • 0

Have been learning about MVP and have tried writing a test app using it in WinForms. I’m struggling to find a well explained example on how to navigate between my forms/views. As an example, the program starts and I want to show a login dialog then go into my main view if the login was successful. At the moment, my Main method looks something like this:

static void Main()
{
   var loginView = Injector.Resolve<ILoginView>();
   if (loginView.DoLogin() != LoginResult.OK) return;
   var mainView = Injector.Resolve<IMainView>();
   Application.Run(mainView); // won't work as mainView isn't a form
}

The Injector object is just a wrapper around an IoC tool (currently StructureMap). The thing is, I’ve read that I shouldn’t really be manually creating instances via the Injector as they should really be done via constructor injection.

I’ve managed to do this up to a point but not when it comes to navigation. I can’t think of an elegant way of moving through my views and was wondering if anyone here might shed some light on this? I’ve read a little on application controllers but have not found an example to show it clearly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:54:02+00:00Added an answer on June 13, 2026 at 10:54 am

    In regards to the navigation question:

    I’ve managed to do this up to a point but not when it comes to
    navigation. I can’t think of an elegant way of moving through my views
    and was wondering if anyone here might shed some light on this? I’ve
    read a little on application controllers but have not found an example
    to show it clearly.

    Below is a simplified version of a construct I’ve used. Note that the setup and tear down hooks are called automatically when the NavigateTo method is called. Also, +1 to @AlexBurtsev, as his answer hints at this very same approach.

    // Presenter can and should offer common services for the
    // subclasses 
    abstract class Presenter
    {
    
       public void Display()
       {
          OnDisplay();
       }
    
       public void Dismiss()   
       {
          OnDismiss();
       }
    
    
       protected virtual OnDisplay() // hook for subclass
       {   
       }
    
       protected virtual OnDismiss() // hook for subclass
       {   
       }
    
       private NavigationManager _navMgr;
    
       internal NavigationMgr NavigationManager
       {   
          get
          {
             return _navMgr;
          }
          set
          {
             _navMgr = value;
          }
    
       }
    
    }
    
    // NavigationManager is used to transition (or navigate) 
    // between views
    class NavigationManager
    {
    
       Presenter _current;
    
       // use this override if your Presenter are non-persistent (transient)
       public void NavigateTo(Type nextPresenterType, object args)
       {   
          Presenter nextPresenter = Activator.CreateInstance(nextPresenterType);   
          NavigateTo(nextPresenter);   
       }
    
       // use this override if your Presenter are persistent (long-lived)
       public void NavigateTo(Presenter nextPresenter, object args)
       {
          if (_current != null)
          {
             _current.Dismiss()
             _current.NavigationMgr = null;
             _current = null;
          }
    
          if (nextPresenter != null)
          {
             _current = nextPresenter;
             _current.NavigationMgr = this;
             _current.Display(args);
          }         
       }
    
    }
    
    
    class MainMenuPresenter : Presenter
    {
    
       private IMainMenuView _mainMenuView = null;
    
       // OnDisplay is your startup hook
       protected override void OnDisplay()
       {
          // get your view from where ever (injection, etc)
          _mainMenuView = GetView();      
    
          // configure your view
          _mainMenuView.Title = GetMainTitleInCurrentLanguage();
          // etc      
          // etc
    
          // listen for relevent events from the view
          _mainMenuView.NewWorkOrderSelected += new EventHandler(MainMenuView_NewWorkOrderSelected);
    
          // display to the user
          _mainMenuView.Show();
       }
    
       protected override void OnDismiss()
       {
          // cleanup
          _mainMenuView.NewWorkOrderSelected -= new EventHandler(MainMenuView_NewWorkOrderSelected);
          _mainMenuView.Close();
          _mainMenuView = null;
       }
    
       // respond to the various view events
       private void MainMenuView_NewWorkOrderSelected(object src, EventArgs e)
       {
          // example of transitioning to a new view here...
          NavigationMgr.NavigateTo(NewWorkOrderPresenter, null);            
       }
    
    }
    
    
    class NewWorkOrderPresenter : Presenter
    {
    
       protected override void OnDisplay()
       {
          // get the view, configure it, listen for its events, and show it
       }
    
       protected override void OnDismiss()
       {
          // unlisten for events and release the view
       }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning about TDD (using JUnit) and I have a doubt about
I have been learning about drawing to panels using bitmaps. I thought I would
I'm just learning about them, and find it discouraging that they have been deprecated.
I have been learning about Delegation and Data Sources for iOS programming and need
Recently I have been learning about WMI and WQL. I found out the list
I have been learning the Definitive Guide of JavaScript.i got a question about the
I am currently learning about basic networking in java. I have been playing around
I've been learning wpf for about a week now.. and i have a basic
I have been learning about various functional languages for some time now including Haskell,
I have recently been learning more about design patterns and thought I'd take a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.