Saturday, July 11, 2009

Introducing: .NET Event Cache

Event Cache Component:

This article introduces a reusable generic event cache that houses events with custom bubbling capabilities. The bubbled events can be defined during runtime in addition to being defined in the normal way as part of a class definition. The event bubbling can be "handled" and stopped by any recipient of the bubbled event. I'll describe the basic architecture of the component and describe how to consume it.

I recently was working on a project where my domain model was a grid structure that needed event bubbling capabilities. I also needed these bubbled events to be handled by any node in the grid so they would stop bubbling. Here was my solutionĂ¢€¦. A cache for events.

The idea is that objects needing to expose this functionality will have an instance of the event cache as a member component. They can then expose whatever functionality is required to perform the work they need to do. Let's first dig into the basic functionality of the event cache and then we'll look at how to implement it in your object model. Finally, I'll show a sample of how to wire up the event bubbling.

EventCache Features:

  • On-the-fly event definition.
  • Event bubbling
  • Event handling so bubbling can be stopped.
  • Contraints in place to ensure there is not a cyclic graph when bubbling events

Simple Samples:

The following sample demonstrates how the event cache can receive event definitions on-the-fly and also then fire them off. All the events in the event cache have a distinct name that is used to lookup the event.


See full detail: http://www.c-sharpcorner.com/UploadFile/rmcochran/EventCache03072009210419PM/EventCache.aspx

No comments: