Model View Presenter, ObjectContainerDataSource and ECO

by john 2/10/2008 8:14:00 AM

I have recently been following the model view presenter pattern when developing web applications. The DataSource components found in ASP.Net won't work, so I began using ObjectContainerDataSource found in the Web Client Software Factory.

I particularly like ECO, a model powered framework for dotnet. I have therefore been investigating using ECO as the model with ObjectContainerDataSource. The datasource component requires that domain objects in the model have a parameterless constructor which I don't believe fits too well with ECO.

I have extended ObjectContainerDataSource by adding events which allow the model to construct the domain objects. 

I figured others might like the results of my investigation so I have placed the the sample code in CodeCentral.

The example is composed of a package with the extended ObjectContainerDataSource component and an ECO powered ASP.Net web application. Persistence is provided by Blackfish.

The web application is composed of 2 webpages.

 AllEmployees.aspx displays a list of employees as can be seen below. Two hyperlinks are available for inserting and editing the selected employee.

 

The second webform is for inserting, editing and deleting employees.

 

Common to each aspx is a Presenter class that handles the interaction between the webform and the model. Thats AllEmployeesPresenter and EmployeePresenter.

Each webform implements an interface through which the presenter moves domain objects back and forth to the model. There is a single model class used by both presenter classes. The model uses ECO as the data access layer.

 One of the primary reasons to use the MVP pattern is that it makes testing easy. I have a unit for each aspx file  that contains unit tests.

The picture below shows ECOMvPWebApplication.dll loaded in NUnit.

 

The tests are exercising the presenter objects. Presenter objects access the user interface through a interface. Objects implementing the interface are passed into the constructor of each presenter.

Each of the WebForms implement the appropriate interface  IAllEmployeeView or IEmployeeView. It would be quite difficult to pass in an actual instance of a webform so I've used NMock a mocking library to provide fake implementations of objects that implement the required interfaces.

The end result is that I can concentrate on directly testing my code. 

Notes

To run the webapplication you should just need to build the projectgroup. I have included the NUnit and NMock runtimes in the lib subdirectory. There is also a copy of the server control assembly from the Web Client software factory.

The sample uses ECO and Blackfish currently available in CodeGears Delphi 2007.

The Blackfish database is in the WebApplications App_Data. You will probably need to modify the database connection string in PersistanceMapperProvider.pas, currently its

 

Self.dataStoreConnection1.ConnectionString := 'host=LocalHost;database=c:\' +  'develop\moshine\ExtendedObjectContainerDataSource\EcoMVPWebApplication\App_Data\EcoWebApplication6.js;user=' +
  'sysdba;password=masterkey;create=false';



Conclusion

In my opinion the following are true:- 

Developing database centric web applications is alot easier and faster using Eco.

Using the MVP pattern makes it easier to test and well tested code is important.

The code for this sample can be found here in CodeCentral

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Blackfish | NMock | TDD | Delphi | CodeGear | MVP | ASP.Net 2.0 | NUnit | ECO

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Name of author John Moshakis
I'm a software developer living in Toronto..

E-mail me Send mail

Calendar

<<  July 2017  >>
MoTuWeThFrSaSu
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Authors

    Tags

    Don't show

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2017

      Sign in