I have just read the design model MVP introduced on msdn. The overall feeling is that it is a bit like MVC. I think the MVP mainly solves the problem of UI control reuse, minimize the business logic involved in the UI Layer. This makes it easier for Project C/S and B/S exchange development because they share the same business layer.
however, this example is somewhat inadequate because its business layer is also related to the control abstraction DTO layer, which makes the business layer more complex. The business layer should only be associated with the presentation layer.
the original system architecture is as follows:
Web. ui interface layer, presentation layer (like business appearance layer), DTO control abstract interface layer, Web. controls control layer, task business layer, dataaccess data access layer, domain data service layer (mainly business data objects ).
You should disconnect the reference between the business layer and DTO, delete the customerdto object in DTO, and replace it with the icustomer of domain. So that the business data objects in the entire application use the domain layer.
modified MVP. task. icustomertask:
Public interface icustomertask
{< br> ilist getcustomerlist ();
icustomer getdetailsforcustomer (INT customerid );
}< br> modified MVP. task. customertask:
public class customertask: icustomertask
{< br> private readonly icustomermapper customermapper;
Public customertask (): This (New customermapper ())
{
}
Public customertask (icustomermapper customermapper)
{
This. customermapper = customermapper;
}
Public ilist getcustomerlist ()
{< br> return customermapper. getallcustomers ();
// new lookupcollection (New customertolookupconverter (). convertallfrom (customermapper. getallcustomers ();
}
Public icustomer getdetailsforcustomer (INT customerid)
{< br> icustomer customer = customermapper. findbyid (customerid);
return customer;
}< BR >}< br> port the Three conversion files in the converters folder to presentation.
modify the presentation layer:
namespace MVP. presentation
{< br> public class viewcustomerpresenter
{< br> private readonly iviewcustomerview view;
private readonly icustomertask task;
Public viewcustomerpresenter (iviewcustomerview view): This (view, new customertask ()){}
Public viewcustomerpresenter (iviewcustomerview view, icustomertask task)
{
This. view = view;
This. Task = task;
}
Public void initialize ()
{
This. getlookupcollection (). bindto (view. customerlist );
}
Private ilookupcollection getlookupcollection ()
{
Ilist <icustomer> ocustomers = task. getcustomerlist ();
Ilist <ilookupdto> olookup = new customertolookupconverter (). convertallfrom (ocustomers );
Return new lookupcollection (olookup );
}
Public void displaycustomerdetails ()
{
Int? Customerid = selectedcustomerid;
If (customerid. hasvalue)
{
Icustomer customer = task. getdetailsforcustomer (customerid. value );
Updateviewfrom (customer );
}
}
Private Int? Selectedcustomerid
{
Get
{
String selectedid = view. customerlist. selecteditem. value;
If (string. isnullorempty (selectedid) return NULL;
Int? Id = NULL;
Try
{
Id = int. parse (selectedid. Trim ());
}
Catch (formatexception ){}
Return ID;
}
}
Private void updateviewfrom (icustomer customer)
{
View. companyName = Customer. companyName;
View. contactname = Customer. contactname;
View. contacttitle = Customer. contacttitle;
View. Address = Customer. address;
View. City = Customer. City;
View. region = Customer. region;
View. Country = Customer. Country. Name;
View. Phone = Customer. Phone;
View. Fax = Customer. Fax;
View. postalcode = Customer. postalcode;
}
}
Reference: http://www.microsoft.com/china/msdn/library/architecture/architecture/architecturetopic/MVP.mspx? MFR = true