In MVP pattern, the challenge part is how to update data back to model/db from view. If view can call the model’s update function directly, it’s so called ‘supervision controller’, as Martin Fowler’s newly suggested. Obviously this might cause tight coupling problem, and also we don’t want both view and presenter can call model’s update function.
If all the update operation have to go through presentor, this pattern becomes to ‘Passive View’. (So nice to know Chinese, Rader’s post explained it very well to me. Though I did read Billy MacCarfferty’s similar one ealier but could not understand completely. )
Now I got it why both JP and Billy adopt DTO in their demo projects. By transfer DTO-only-data between presenter and view, all the update operation will be centralized to presenter then.
Billy’s idea of ‘Update method in view’ might solve my problem: all the update operations have to go through stored procedure which needs both original and new data as calling parameters. Presentor should have no problem to get all of them, old data from model and new data from view.
As other reader pointed out, in Billy sample code, the presenter’s constructor really confused people.
Which means presenter needs to instantiate Dao layer stuff? Billy added a SessionFactoryConfigPath parm in DaoFactory’s constructor, this forced me created a dbConfig.cs in data layer and overrode constructor to make web and presenter both db-config-free.
This also reminds me Steven Yang and JP’s code in which they added a service layer or task layer to entity object back to presenter. Like Jeremy’s sample,
Presenter(IWorkItemView view, IWorkItemService service)
JP did the same thing in his MVP sample, without NHibernate, he put connection string in DataAccess layer.
public class DbConnectionFactory : IDbConnectionFactory
public IDbConnection Create()
IDbConnection connection = DbProviderFactories.GetFactory(“System.Data.SqlClient”).CreateConnection();
// “data source=(local);Integrated Security=SSPI;Initial Catalog=EnterprisePatternsEdmonton”;
“data source=’.\\SQLEXPRESS’;Integrated Security=SSPI;Initial Catalog=Northwind”;
I think this is the right place to configure db, should not be in web, or somewhere else.
In fact, in his task layer, the FindById and FindAll / GetList could be done by NHinberat.Generic. We might cut down one extra layer then.