/// <summary>
        /// Create a new bus that will use the sender and reciever provided communication outside of the buses context
        /// </summary>
        /// <param name="messageSender">Shared isntance of the sender</param>
        /// <param name="messageReceiver">Shared instance of the receiver</param>
        public MessageBus(IMessageSender messageSender,
                          IMessageReceiver messageReceiver)
        {
            m_Lock        = new object();
            m_Subscribers = new Dictionary <Type, Delegate>();

            m_MessageSerialiser = new MessageSerialiser();
            m_MessageSerialiser.Register(typeof(SetPathToTarget));
            m_MessageSender   = messageSender;
            m_MessageReceiver = messageReceiver;

            m_Disposer = new Disposer();

            m_MessageReceiver.AddListener(ReceiveFromRemote).AddTo(m_Disposer);

            m_Messages = new ConcurrentQueue <IMessage>();
        }
Beispiel #2
0
        /// <summary>
        /// Create a new bus that will use the sender and reciever provided communication outside of the buses context
        /// </summary>
        /// <param name="messageSender">Shared isntance of the sender</param>
        /// <param name="messageReceiver">Shared instance of the receiver</param>
        /// /// <param name="messageList">The collection of message types to register for serialisation</param>
        public MessageBus(IMessageSender messageSender,
                          IMessageReceiver messageReceiver,
                          IMessageRegistrationList messageList)
        {
            m_Lock        = new object();
            m_Subscribers = new Dictionary <Type, Delegate>();

            m_MessageList     = messageList;
            m_MessageSender   = messageSender;
            m_MessageReceiver = messageReceiver;

            m_MessageSerialiser = new MessageSerialiser();
            foreach (var messageType in m_MessageList.Messages)
            {
                m_MessageSerialiser.Register(messageType);
            }

            m_Disposer = new Disposer();

            m_MessageReceiver.AddListener(ReceiveFromRemote).AddTo(m_Disposer);

            m_Messages = new ConcurrentQueue <IMessage>();
        }