Introduction
Setting up a NavWin MVP project is designed to be really
fast and easy. The project will work as both a Windows application (for fast
testing and development) and also a Web application. The project uses Windows
User Controls for designing the view layout. The controls are used directly in
the Windows version of the project and the layout is used directly in the web
version of the project. Each project can have as many presenters as needed and
these are easily linked together using the three core navigation methods
- NWChangePresenter (new presenter)
- NWUpdatePresenter()
- NWGoBackPresenter()
You can either put all your presenters in a single ‘big’
project or you can break them up into multiple Visual Studio projects. In
general it is recommended that you have one Visual Studio project per distinct
Web application. This means each application can be developed independently of
all the others. As you finish an application, you can simply include your
project into a single ‘master’ web project and select one top-level
application. In the NavWin web site, we have made an application called
‘AppSelector’ which is simply a stateless application that allows you to
navigate to the other applications.
Steps to make a stateless starter project
A stateless starter project does not require any model to
preserve the state when the user navigates away from the view. For completeness
we include an empty model class below but this can be deleted if it remains
unused
1) Create
a normal Class Library project, we will call ours NavWin.MVP.MyAppName
2) Rename
the default class to ModelMyAppName.cs (delete this class if your app
does not require any state to be stored)
3) Add
a reference to the assembly NavWin.MVP.Framework
4) Add
a ‘using’ to NavWin.MVP.Framework to this class
|
using
NavWin.MVP.Framework.Model;
|
5) For
now, just add one User Control item to represent the top level presenter.
Call the user control PresenterMyAppName.cs
6) Add the
following ‘using’ to statements to this class
|
using
NavWin.MVP.Framework.WinControls;
using NavWin.MVP.Framework.Model;
|
7) Important
– Change the top level class declaration of the user control from
|
public
partial class
PresenterMyAppName : UserControl
|
to
|
public
partial class
PresenterMyAppName : NWBasePresenter
|
8) Add
the following method to the presenter (this is the minimum you need)
|
public
override void
NWInitialisePresenter()
{
}
|
9) Using
the normal Visual Studio user control designer, create a control layout using
the special ‘NW’ web controls e.g. here is the design for the NavWin login
presenter

10) To test this control as
Windows application, add a new Windows Application project to the
solution.
a. Set
this project as startup
b. Add
a reference to the assembly NavWin.MVP.Framework
c. Add
a reference to the project NavWin.MVP.MyAppName
d. In
the form load event, add the following code, use a suitable location to store
your test data (this location is used for all models)
|
private
void Form1_Load(object
sender, EventArgs e)
{
NWModel.ModelDirectory = @"D:\Work\TestData";
PresenterMyAppName presenter
= new PresenterMyAppName();
this.Controls.Add(presenter);
presenter.NWResizeControls();
}
|
e. Run
the Windows application and you will see the following

11) Before we enable this
application as a web application, we need to define one more special class which
is a unique requirement to a stateless Web application. This is called the
presenter router class. This class can take the information in a URL in order
to identify the correct presenter to use in any one client request.
a. Create
a class called RouterMyAppName
b. Add
a ‘using’ to NavWin.MVP.Framework to this class
|
using NavWin.MVP.Framework.WinControls;
|
c. Change
the class declaration to implement the INWPresenterRouter interface
|
public class RouterMyAppName : INWPresenterRouter
|
d. Add
the following method to implement the interface. Note in this example there is
only one presenter so the ‘presenterName’ argument is ignored
|
public
const string
APPLICATION_NAME = "MyAppName";
public
NWBasePresenter GetPresenter(string presenterName, List<string> parameters)
{
return new PresenterMyAppName();
}
|
12) To test this control
in as Web application, add a new Web Application project to the solution
a. Set
this project as start-up
b. Add
a reference to the assembly NavWin.MVP.Framework
c. Add
a reference to the project NavWin.MVP.MyAppName
d. In
addition to the Default.Aspx form, add a second form called Response.Aspx.
Note that you will only need these two forms to drive the entire web
application. The Default.Aspx is the start up form. The Response.Aspx is the
callback form and this is never displayed to the user.
e. In
the page load event for the Default.Aspx add the following bootstrap code
|
public partial
class WebApps
: System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
NWMessageHandler handler = new NWMessageHandler();
handler.ProcessPageLoad(this, "Response.Aspx");
}
}
|
f.
In the page load event of the Response.Aspx add the following client
call back code. The code can be extended to as many routers as you want,
depending on how many applications you support (just add more ‘if’ conditions).
There is always one router per application.
|
NWPresenterRouter router = null;
NWMessageHandler handler = new NWMessageHandler();
NWRequestUrl url = handler.ParseUrl(this);
if
(url.ApplicationName == String.Empty)
{
router = new RouterMyAppName();
// default router
}
else
if (url.ApplicationName == RouterMyAppName.APPLICATION_NAME)
{
router = new RouterMyAppName();
}
handler.ProcessResponse(this, router, url, "WebApps.Aspx");
|
g. You
can now run the Web application and you will see this screen
