Created
          April 10, 2012 12:17 
        
      - 
      
 - 
        
Save dtryon/2350988 to your computer and use it in GitHub Desktop.  
    Simple Bus implementation
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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