Skip to content

Instantly share code, notes, and snippets.

@dtryon
Created April 10, 2012 12:17
Show Gist options
  • Save dtryon/2350988 to your computer and use it in GitHub Desktop.
Save dtryon/2350988 to your computer and use it in GitHub Desktop.
Simple Bus implementation
public class Bus : IBus
{
// this is our dependency that will publish the message to a queue (or somewhere else)
private IMessageDispatcher messageDispatcher;
public void Publish<T>(Action<T> action) where T : IMessage
{
var newInstance = CreateInstance<T>();
// pass the new instance to the action (by reference)
action(newInstance);
messageDispatcher.Publish(newInstance);
}
private T CreateInstance<T>()
{
var result = default(T);
// do something clever creating an initialized T instance
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment