CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

David Hayden [MVP C#]

         .NET Tutorials, Patterns, and Practices

Model-View-Presenter and GridView via ObjectContainerDataSource Control

A little before and right after the Tampa CodeCamp I took about 10 days off to do some work around the house as well as hang with the kids at the beach, so I am a bit late with this post regarding the Tampa CodeCamp.

I posted my Tampa CodeCamp presentation slides on the Web Client Software Factory on the PnPGuidance Website. The sample code showing off the WCSF with Enteprise Library is there, too.

I received a question via email about the value of the ObjectContainerDataSource Control in my example. The ObjectContainerDataSource Control is a custom DataSource Control provided by the Patterns & Practices Team in the WCSF that is Model-View-Presenter Friendly.

If you think about the ObjectDataSource Control that is provided in System.Web, it requires and calls a type typically in the business logic layer that implements select, insert, update, and delete methods. When implementing Model-View-Presenter, however, you want the View to delegate events to the Presenter Class where it will respond to any UI events. The ObjectContainerDataSource Control makes this possible by publishing events that can then be easily delegated to the Presenter Class.

Here are some code snippets from the sample code available for download mentioned above:

 

protected void Page_Init(object sender, EventArgs e)
{
    // CustomerDataSource is an ObjectContainerDataSource
    CustomerDataSource.Inserted += new EventHandler(CustomerDataSource_Inserted);
}

void CustomerDataSource_Inserted(object sender, ObjectContainerDataSourceStatusEventArgs e)
{
    _presenter.OnInsert((Customer) e.Instance);
}

 

Notice how you can just subscribe to the insert, update, delete, and select events of the ObjectContainerDataSource Control and then pass those events to the Presenter Class. This is a lot more Model-View-Presenter Friendly than your normal ObjectDataSource Control. Note that passing the Customer Instance to the Presenter in the OnInsert Method is purely optional. Most people prefer that the Presenter Class request the Customer Instance separately.

Just thinking out loud here, but I wonder if the Patterns & Practices Team can do something that gives us a Model-View-Presenter Friendly LinqDataSource Control as well. Hmm....


Published Jul 27 2007, 10:18 PM by David Hayden
Filed under:

Comments

David Hayden said:

Lance,

I have created Views both ways, using events or delegation, and both work fine. I haven't come across an argument for using one over the other so far with webforms.

Since the Web Client Software Factory uses the delegation route as opposed to events, I just normally use that method when working with it.

Either is fine and the ObjectContainerDataSource Control will work both ways.

# August 5, 2007 10:02 PM
Check out Devlicio.us!

This Blog

Syndication

News

CodeBetter.Com Home