WPF and n-level design

C

Craig Lister

Hi guys,

I am about to build a desktop application. Single user, but using a
database. At the moment, it's SQL Server, but may change to CE or
something small and compact.

I am coding my data access, business and service layers. For the
presentation, I was thinking of using WPF. I have never used it, so I
have no idea what I am in for - but is it OK to fit that on top of my
current design of my data access, business and service layer? Or is
there a different design needed for WPF?
 
M

Mr. Arnold

Craig said:
Hi guys,

I am about to build a desktop application. Single user, but using a
database. At the moment, it's SQL Server, but may change to CE or
something small and compact.

I am coding my data access, business and service layers. For the
presentation, I was thinking of using WPF. I have never used it, so I
have no idea what I am in for - but is it OK to fit that on top of my
current design of my data access, business and service layer? Or is
there a different design needed for WPF?

The way to do it is to use a Model View Presenter pattern to decouple
the UI and use loose coupling, which can be done with Web or Windows
desktop UI.

http://en.wikipedia.org/wiki/Model_View_Presenter

http://www.codeproject.com/KB/architecture/MVP_WPF_UtilityContainer.aspx
http://www.paulstovell.com/wpf-model-view-presenter

UI
Presenter
BLL
Service
DAL

The site shows you have to do an MVP for Web or Windows desktop app.

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click 'Shows'

click 'Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5

The above show uses events, but I like the MVP that does Object
injection into the presenter with the View and Service where you
directly call a method on the presenter from the UI instead of using
events. The service part in the show you can use in the object injection
presenter, passing view and service instance into the presenter.

One of these links below show the presenter using object injection
instead of event driven. It's a link within one of the links. I can't
find it, and I am tired of looking for it. But it's there somewhere. Or
maybe you can hit Google to see and example.

The wikipedia link above there is using object injection of the view
into the presenter, limited example.

<http://msdn.microsoft.com/en-us/magazine/cc188690.aspx>
<http://mrrask.files.wordpress.com/2008/01/model-view-presenter.pdf>
<http://www.mvcsharp.org/Reworking_ASPNET_MVC_Store/Default.aspx>
<http://www.codeproject.com/KB/aspne...lect=2822806#Reusing the presenter in windows>
<http://codebetter.com/blogs/jeremy....net-and-the-model-view-presenter-pattern.aspx>


I don't know if you can use MVP with CE, maybe.
 
C

Craig Lister

Thanks all..

Checking all the links. Ta.

Does this really just present a new 'presentation' layer, between the
GUI and maybe my Service layer?

I currently have:

GUI
Makes a call to Service layer: List<Products> = Service.GetProducts();

Service
Makes a call to Business:
List<Products> = Business.GetProducts();

Business:
Makes a call to Data Access:
List<Products> = DataAcess.GetProducts();

DataAccess:
DataReader = Database.CallProcToGetProducts();

So, to make use of WPF, I need to add a new layer ABOVE service, and
BELOW GUI, which makes calls to the Service, but that returns
different stuff to the GUI?

Does this seem right?
 
T

Tom Shelton

Thanks all..

Checking all the links. Ta.

Does this really just present a new 'presentation' layer, between the
GUI and maybe my Service layer?

I currently have:

GUI
Makes a call to Service layer: List<Products> = Service.GetProducts();

Service
Makes a call to Business:
List<Products> = Business.GetProducts();

Business:
Makes a call to Data Access:
List<Products> = DataAcess.GetProducts();

DataAccess:
DataReader = Database.CallProcToGetProducts();

So, to make use of WPF, I need to add a new layer ABOVE service, and
BELOW GUI, which makes calls to the Service, but that returns
different stuff to the GUI?

Does this seem right?

You might want to look in to MVVM (Model-View-View Model) - this seems to be
the current pattern for WPF GUI's. I'd give you more, but I'm still working
it out my self :)
 
M

Mr. Arnold

Craig said:
Thanks all..

Checking all the links. Ta.

Does this really just present a new 'presentation' layer, between the
GUI and maybe my Service layer?

Yes, but the presenter layer doesn't have to be a new project, but
rather a new Folder in the UI.
I currently have:

GUI
Makes a call to Service layer: List<Products> = Service.GetProducts();

The GUI will call the presenter and the presenter calls the service
Service
Makes a call to Business:
List<Products> = Business.GetProducts();
Ok

Business:
Makes a call to Data Access:
List<Products> = DataAcess.GetProducts();

DataAccess:
DataReader = Database.CallProcToGetProducts();
Ok

So, to make use of WPF, I need to add a new layer ABOVE service, and
BELOW GUI, which makes calls to the Service, but that returns
different stuff to the GUI?

In order to use N-tier and WPF, you use MVP that sits between the UI and
the service layer, as shown in the examples given to you.

I suggest you take the MVP show parts 1-6, and then it becomes clear as
to what is happening with MVP.
Does this seem right?

I don't know what you mean by different stuff, other than, you're
calling different methods in the Service layer for CRUD on Shippments as
to Products, if both were need by the application for the UI page.

The presenter sits between the UI and service, as that is the pattern we
use at work for ASP.NET solutions.

UI
Presenter
Services
WCF services
BLL
DAL

You'll notice that the BLL and DAL sit behind the WCF service. The
presenter calls a liked named method in the services layer, the services
method calls a liked named service on the WCF service, the WCF class a
liked named method in the BLL and the BLL calls a liked named method in
the DAL.

You want to call it GetProducts(), then so be it.

Let's say as an example a GridView control on the is a a Web page.

Let's say the GridView was to be loaded on Page_Load.

IView as a getter for the GridView..

public interface IView
{

GridView TheGridView {get;}
}


Now that Web page itself must implement IView, and it going to implement
a get Interface for TheGridView.


class ProductPage :IView
{

public GridView TheGridView
{
get {return GridView1; } // the actual control name of the form
GridView1


protected Page_Load(sender object, evtargs e)
{

mpresenter.PageLoad();
}


ProductPage passes and instance of itself and a instance of the service
in the service layer.

public Presnter()
{
public void PageLoad()
{
mview.TheGridView.Datasource = mservice.GetProducts();
mview.TheGridView.DataBind();
}
}


GridView1 is now populated and given back to the page

That's one way of doing it with MVP.

In some cases, the Presenter has some business rules in it. The Web UI
pages we use are dumb UI(s). And all they do is pass control to a
Presenter.Method().
 
A

Andy O'Neill

Craig Lister said:
Thanks all..

Checking all the links. Ta.

Does this really just present a new 'presentation' layer, between the
GUI and maybe my Service layer?

I currently have:

GUI
Makes a call to Service layer: List<Products> = Service.GetProducts();

Service
Makes a call to Business:
List<Products> = Business.GetProducts();

Business:
Makes a call to Data Access:
List<Products> = DataAcess.GetProducts();

DataAccess:
DataReader = Database.CallProcToGetProducts();

So, to make use of WPF, I need to add a new layer ABOVE service, and
BELOW GUI, which makes calls to the Service, but that returns
different stuff to the GUI?

Does this seem right?

For a single user application this seems very complicated.

I develop in WPF, in fact I am doing so at the moment..
MVP is nearly MVVM, the difference is that MVVM uses the binding
capabilities of WPF.
I very strongly recommend MVVM over MVP because you write less code.
MVVM is IME clearly better suited to WPF and that is why people have changed
from MVP to MVVM.

The way your stuff should work is that the View (gui) knows nothing about
data access or anything much.
You don't need hardly any code behind it at all.
The view just calls some commands and binds to fields.
The big thing to get your head round is the way binding fires events when
the data changes.
So when you're thinking of a button think command or bound property in the
viewmodel.
Should you find yourself writing an event handler in the view, don't.

The next layer is your view model.
This has business logic in it and exposes objects to the view.
I'll gloss over commands and exactly how you make the view model do stuff.
The view model handles calls to services or whatever.

The Model can pretty much just be definitions of your types and maybe
provide pointers to where your data is if you intend switching.

I am wondering why you have a web service at all for a single user system.
This is the sort of architecture I'd look at for thousands of concurrent
users rather than one single one.
If that reason is the user is remote and may therefore lose connectivity
then I would go for sql ce on the client.
Write data to that and then propagate back to the server later.

You want to watch several videos.
First, the silverlight one and then the wpf one here.
http://weblogs.asp.net/craigshoemak...w-viewmodel-mvvm-for-silverlight-and-wpf.aspx

You will find that Josh is a very clever bloke but maybe a bit too clever
for the newb.
Then find the Jason Dollinger video.
Then there's Josh's msdn magazine article. BUT watch the rest and be aware
that this last one will blow your mind if you don't have a reasonable
understanding first.
 
M

Mr. Arnold

Andy said:
I am wondering why you have a web service at all for a single user system.
This is the sort of architecture I'd look at for thousands of concurrent
users rather than one single one.

It's not a Web service. It's a service layer. The service layer has
classes and methods in the classes to make the call to the data stor.

The data stor can be a DAL that the service layers calls directly or BLL
to DAL direct call to the BLL by the service.

It can be a Web service that the service layer calls to access the BLL
to DAL behind the Web service or call just to the DAL.

The service layer can make calls to a WCF Web service, WCF Named Pipe
service, WCF TCP/IP service or WCF MSMQ service.

The service layer is an abstraction layer that sits between the
front-end and the back-end on a n-tier with physical separation of the
tiers --tiers on different machines. Or it can be a logical n-tier
separation where all tiers set on the single machine.

The service layer can be for an application for single user usage or
mutil user usage based on the needs of the application.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top