Mats Lycken development

.NET and web related blog posts

NAVIGATION - SEARCH

Adding communication between user controls without involving the web form

One problem I've faced with the model-view-presenter pattern is how to add communication between different user controls on a web form without adding a bunch of logic to the web form. Ideally the web form shouldn't be aware that the user control is there, the user control should be able to load it's data and update the model by itself.

My solution to this problem was to create a custom object builder attribute - CreateShared.

The CreateShared attribute functions the same way as CreateNew except that it will only create one instance / request for the requested type. This can for instance be used in presenters to create a shared instance of the controller.

By doing this you can add events to the controller which reflects changes in the model. The different presenters can listen to these events and respond to changes made by another presenter. This is how you can perform the communication.

You can read a How-To and a description of the sample on the Wiki page on codeplex.com. Read it here.

Attached to this entry is both the code and a sample that shows how to use it. Both projects are Visual studio 2008 projects and references Web Client Software Factory 2.0 feb 2008.

CreateShared.zip (31,89 kb)
CreateShared - Sample.zip (742,89 kb)

Comments (1) -

Mats,

Thank-you for providing this solution to the community!  I can assure everyone that it works as expected.

See computercraft.co.nz/.../...aringTheController.aspx

Reply

Add comment