views:

53

answers:

1

Not sure if there is a "correct" answer to this, so I've flagged it as community wiki. Apologies for the long pre-amble.

I am building a modestly sized web application in .Net, and have settled on a table based architecture. My DAL layer consists of a set of TableGateway classes that handle loading/saving data to the database - these return strongly typed DataSets. Application logic is organised into a set of TableModule classes. Finally my ASPX pages handle displaying stuff and passing form values etc. to the TableModules to be worked on.

What puzzles me is who should take responsibility for calling the TableGateway to get the DataSet, the ASPX code-behind or the TableModule?

Example 1 - ASPX does it:

SomePage.aspx.cs:

    protected void AddLink_Click(object sender, EventArgs args)
    {
        long id = long.Parse(PopulationDropDown.SelectedValue);
        string someProperty = SomePropertyTextBox.Text;

        IPopulationGateway populationGateway = DALServicesLocator.GetPopulationGateway();
        PopulationDataSet populationData = populationGateway.LoadPopulationDetails(id);

        PopulationModule.SomeLogicToAddStuff(populationData, id, someProperty);

        populationGateway.Save(populationData);
    }

Example 2 - TableModule does it:

SomePage.aspx.cs:

    protected void AddLink_Click(object sender, EventArgs args)
    {
        long id = long.Parse(PopulationDropDown.SelectedValue);
        string someProperty = SomePropertyTextBox.Text;

        // Just pass values to the TableModule and let it talk to the Gateway.
        PopulationModule.SomeLogicToAddStuff(id, someProperty);
    }
A: 

IMHO 2nd variant, because it simple to split logical layers as MVC model:

  • aspx page is View, only translates data and commands from and to user representation

  • TableModule acts like Controller layer

  • TableGateway represents Model layer

In second variant you can modify access mode in Control layer, based on internal conditions, not accessible for aspx level. E.g. decide from which id really load data, check for user access rights etc.

ThinkJet