Simple Pipeline Event model with C#

By on 8/22/2009

After declaring my love for extension methods in the last post, it only seemed appropriate that it would come up again in an answer I gave to a stackoverflow question.  The question stated:

In ASP.NET Web Apps , events are fired in particluar order :

for simplicity Load => validation =>postback =>rendering

Suppose I want to develop such pipeline -styled event

Example :

Event 1 [ "Audiance are gathering" ,Guys{ Event 2 and Event 3 Please wait until i signal }]

after Event 1 finished it task

Event 2 [ { Event 2, Event 3 "Audiance gathered! My task is over } ]

Event 2 is taking over the control to perform its task

Event 2 [ " Audiance are Logging in " Event 3 please wait until i signal ]

after Event 2 finished it task


Event 3 [ "Presentation By Jon skeet is Over :) "]

With very basic example can anybody explain ,how can i design this ?

My answer again leveraged an extension method to simplify the notification of events to each individual handler:

public abstract class Handler
  public abstract void Handle(string event);

public static class HandlerExtensions {   public static void RaiseEvent(this IEnumerable<Handler> handlers, string event)   {      foreach(var handler in handlers) { handler.Handle(event); }       } }


List<Handler> handlers = new List<Handler>(); handlers.Add(new Handler1()); handlers.Add(new Handler2());

.RaiseEvent("event 1"); handlers.RaiseEvent("event 2"); handlers.RaiseEvent("event 3");

See more in the archives