in

Drowning In Technical Debt

C# | ASP.NET | SharePoint | SQL | Architecture | SOA |

David Strommer

Generics CommandHandler

http://udidahan.weblogs.us/archives/036867.html

 
Udi Dahan demonstrates how to leverage Generics for Command Handling, NICE.
 
Excerpt:

public class CommandHandler<T> where T : IEntity
{
   public CommandHandler()
   { 
      NewCommand.Activated += delegate(object sender, EntityEventArgs e)   
   
      { 
         if (e.EntityType == typeof(T)) 
         { 
            IView v = this.builder.Build<IEntityView<T>>(); 
            
v.Show(); 
         }
      };
   }
}

and then you'd just instantiate a command handler for each entity type like so:

new CommandHandler<Customer>();
new CommandHandler<Order>();

Published Oct 14 2006, 03:04 PM by David Strommer
Filed under:

Comments

No Comments
Powered by Community Server (Commercial Edition), by Telligent Systems