Tuesday, June 16, 2009

MVC Declarative Binding

One of the things that makes the bar to implement any "MVC-ish" pattern high is the tremendous amount of plumbing required just to get started in order for the different entities to communicate state changes. This article introduces a utility library that can be used to declaratively bind the model and view encapsulating all the wiring required and making implementation much easier.

Here's how to consume the library:

The idea is to declaratively bind property and collection change events. I have created two attributes for this: BoundToPropertyAttribute and BoundToCollectionAttribute. We can either define these on an interface the view will implement (which is the usage I prefer) or we can declare the attributes on the concrete view.

public interface IPersonView
[BoundToProperty(typeof(Person), "Name")]
String Name { get; set; }

void FriendsAdded(IEnumerable<Person> people);

void FriendsRemoved(IEnumerable<Person> people);

void FriendsReset(IEnumerable<Person> people);

See full detail: http://www.c-sharpcorner.com/UploadFile/rmcochran/MVCDeclarativeBinding06072009124427PM/MVCDeclarativeBinding.aspx

No comments: