need help for IMessageManager

Topics: Core, General, Troubleshooting
May 23, 2012 at 2:47 PM

  public DefaultMessageManager(            IMessageEventHandler messageEventHandler,            IEnumerable<IMessagingChannel> channels)

 private void PrepareAndSend(string type, Dictionary<string, string> properties, MessageContext context) {            try {                if (properties != null) {                    foreach (var key in properties.Keys)                        context.Properties.Add(key, properties[key]);                }

                _messageEventHandler.Sending(context);
                foreach (var channel in _channels) {                    channel.SendMessage(context);                }
                _messageEventHandler.Sent(context);            }            finally {                context.MailMessage.Dispose();            }
            Logger.Information("Message {0} sent", type);        }

------------

why it is not :

  public DefaultMessageManager(           IEnumerable< IMessageEventHandler  > messageEventHandlers,            IEnumerable<IMessagingChannel> channels)

 

 private void PrepareAndSend(string type, Dictionary<string, string> properties, MessageContext context) {            try {                if (properties != null) {                    foreach (var key in properties.Keys)                        context.Properties.Add(key, properties[key]);                }

                foreach (var messageEventHandler in __messageEventHandlers) {  

messageEventHandler.Sending(context);


                foreach (var channel in _channels) {           

        channel.SendMessage(context);         

      }

  foreach (var messageEventHandler in __messageEventHandlers) {  
                messageEventHandler.Sent(context); 

    }       } 

          finally {                context.MailMessage.Dispose();            }
            Logger.Information("Message {0} sent", type);        }

---------------

because we have 3 (or More) class which implemet IMessageEventHandler

EmailMessageEventHandler : IMessageEventHandler

 MailActionsHandler : IMessageEventHandler

 

UserMessagesAlteration : IMessageEventHandler

 

Coordinator
May 23, 2012 at 4:52 PM

IMessageEventHandler implements IEventHandler, which means it will be called through the event bus. And there is a specific mecanism here that when you require such a dependency, it will actually give you a fake one, which will send messages ti the bus, and every implementation which has the same signature, i.e. the same interface+method name.

So at the end it's completely equivalent.