/// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public ServiceBus(ServiceBusConfiguration configuration)
        {
            if (configuration.ServiceLocator == null)
            {
                throw new ArgumentException("Service Locator doesn't registered. Use SetServiceLocator() method.");
            }

            if (configuration.InputQueue == null)
            {
                throw new ArgumentException("Input queue not configured. Use SetInputQueue() method.");
            }

            _configuration = configuration;
            _provider      = configuration.Transport;
            _inputTransportEndpointAddress = configuration.InputQueue;
            _errorTransportEndpointAddress = configuration.ErrorQueue;
            _endpointMapping = configuration.EndpointsMapping;

            // use container of ServiceBus, if not specified for dispatcher
            if (_configuration.DispatcherConfiguration.ServiceLocator == null)
            {
                _configuration.DispatcherConfiguration.ServiceLocator = configuration.ServiceLocator;
            }

            TransportRegistry.Register(_inputTransportEndpointAddress, _provider);
            TransportRegistry.Register(_errorTransportEndpointAddress, _provider);
        }
        /// <summary>
        /// Run service bus and start input endpoint observing
        /// </summary>
        public void Run()
        {
            // Registration of endpoints
            foreach (var endpoint in _endpointMapping.Endpoints)
            {
                if (TransportRegistry.GetQueueProvider(endpoint.Address) == null)
                {
                    TransportRegistry.Register(endpoint.Address, endpoint.Transport ?? _provider);
                }
            }

            // Check existence of input and error endpoint and create them if needed
            PrepareQueues();

            // Create dispatcher
            _dispatcher = new Dispatcher(_configuration.DispatcherConfiguration);

            // Open error queue
            _errorTransportEndpoint = _provider.OpenEndpoint(_errorTransportEndpointAddress);

            // Create and configure observer of input queue
            _transportEndpointObserver = _provider.CreateObserver(_inputTransportEndpointAddress);
            _transportEndpointObserver.MessageReceived += EndpointObserverMessageReceived;
            _transportEndpointObserver.Start();

            // Set servise bus state into Running state
            _status = ServiceBusStatus.Running;
        }