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. 


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=' +


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


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

ASP.Net Profiles, Anonymous Users and ProfileCommon

by john 11/25/2007 5:33:00 AM

Its easy storing user specific information using the profile feature. When writing web sites as opposed to web applications a strongly typed object called profile is added to the webpage. This object defines a mapping to the profile section in web.config.

For example 

        <profile defaultProvider="AspNetAdoProfileProvider">
                <group name="UserDetails" >
                  <add name="State"   type="System.String" allowAnonymous="true" />

Would be

self Profile.UserDetails.State in your Delphi codebehind, unfortunately Delphi only supports web applications.

so your left with a more verbose version which would be


This is not something I'm going to easily remember, so its Class Helpers to the rescue again.


I started off by adding a Profile property to my webpage base class.


    function get_Profile: ProfileBase;

    property Profile:ProfileBAse read get_Profile;


function ProfileWebApplicationPage.get_Profile: ProfileBase;


And I then introduced the first class helper for Profilebase

  ProfileCommon=class helper for ProfileBase
    function GetProfile(username:string):ProfileBase;virtual;
    function get_ProfileGroupUserDetails: ProfileGroupBase;
    property UserDetails:ProfileGroupBase read get_ProfileGroupUserDetails;

and then a second for  ProfileGroupBase


  ProfileGroupUserDetails=class helper for ProfileGroupBase
    public property Zip: string read get_Zip write set_Zip;
    public property Address: string read get_Address write set_Address;
    public property City: string read get_City write set_City;
    public property Email: string read get_Email write set_Email;
    public property GetNewsletter: boolean read get_GetNewsletter write set_GetNewsletter;
    public property Phone: string read get_Phone write set_Phone;
    public property State: string read get_State write set_State;

And now the the following will appear in Code Completion and Compile

  anonymousProfile := Profile.GetProfile(args.AnonymousID);

  if (Profile.LastActivityDate = DateTime.MinValue)then
    Profile.UserDetails.Address := anonymousProfile.UserDetails.Address;


 The full source for the example can be found in codecentral. This example also demontrates how anonymous profiles can be migrated to a new website user using the Profile_OnMigrateAnonymous event in Global.asax


If you run the example default.aspx should be displayed in your browser



You have entered the site as an anonymous user, you can now click on the profile link and head over to the profile page. In this page you enter your profile and hit the save button.

You are now ready to use the create user menu option. If you enter your new user details and hit the create user button you end up here.


When the user hits the continue button the Profile_OnMigrateAnonymous event is fired and the code inside the event handler in Global.asax is executed.

  anonymousProfile := Profile.GetProfile(args.AnonymousID);

  if (Profile.LastActivityDate = DateTime.MinValue)then
    Profile.UserDetails.Address := anonymousProfile.UserDetails.Address;
    Profile.UserDetails.City := anonymousProfile.UserDetails.City;

    Profile.UserDetails.State := anonymousProfile.UserDetails.State;
    Profile.UserDetails.Zip := anonymousProfile.UserDetails.Zip;
    Profile.UserDetails.Email := anonymousProfile.UserDetails.Email;
    Profile.UserDetails.Phone := anonymousProfile.UserDetails.Phone;
    Profile.UserDetails.GetNewsletter := anonymousProfile.UserDetails.GetNewsletter;



This code migrates the profile for the anonymous user over to the newly created user.


Currently rated 1.0 by 1 people

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


Blackfish | Delphi | ASP.Net 2.0 | Providers

Powered by BlogEngine.NET
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


<<  August 2022  >>

View posts in large calendar


    Recent posts

    Recent comments



    Don't show


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

      © Copyright 2022

      Sign in