/// <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>
        /// Factory method. Create service bus.
        /// </summary>
        public static IServiceBus Create(Func <ServiceBusConfiguration, ServiceBusConfiguration> configurationAction)
        {
            var config = new ServiceBusConfiguration();

            configurationAction(config);
            return(new ServiceBus(config));
        }
        /// <summary>
        /// Configure dispatcher
        /// </summary>
        public static ServiceBusConfiguration Dispatcher(this ServiceBusConfiguration configuration, Func <DispatcherConfiguration, DispatcherConfiguration> configurationAction)
        {
            var dispatcherConfiguration = new DispatcherConfiguration();

            dispatcherConfiguration.SetServiceLocator(configuration.ServiceLocator);
            configurationAction(dispatcherConfiguration);

            configuration.DispatcherConfiguration = dispatcherConfiguration;
            return(configuration);
        }
        /// <summary>
        /// Factory method. Create and run service bus
        /// </summary>
        public static IServiceBus Run(Func <ServiceBusConfiguration, ServiceBusConfiguration> configurationAction)
        {
            var config = new ServiceBusConfiguration();

            configurationAction(config);
            var bus = new ServiceBus(config);

            bus.Run();
            return(bus);
        }
        /// <summary>
        /// Set name of Input Endpoint
        /// </summary>
        public static ServiceBusConfiguration SetInputQueue(this ServiceBusConfiguration configuration, String queueName)
        {
            configuration.InputQueue = new TransportEndpointAddress(queueName);

            // If error queue is not defined, set error queue name based on input queue name:
            if (configuration.ErrorQueue == null)
            {
                var errorQueueName = String.Format("{0}.Errors@{1}", configuration.InputQueue.Name, configuration.InputQueue.ComputerName);
                configuration.ErrorQueue = new TransportEndpointAddress(errorQueueName);
            }

            return(configuration);
        }
 /// <summary>
 /// Use memory transport (async)
 /// </summary>
 public static ServiceBusConfiguration MemoryTransport(this ServiceBusConfiguration configuration)
 {
     configuration.Transport = new InMemoryTransport();
     return(configuration);
 }
 /// <summary>
 /// Set number of worker threads
 /// </summary>
 public static ServiceBusConfiguration SetNumberOfWorkerThreads(this ServiceBusConfiguration configuration, Int32 number)
 {
     configuration.NumberOfWorkerThreads = number;
     return(configuration);
 }
 /// <summary>
 /// Set name of Error Endpoint
 /// </summary>
 public static ServiceBusConfiguration SetErrorQueue(this ServiceBusConfiguration configuration, String queueName)
 {
     configuration.ErrorQueue = new TransportEndpointAddress(queueName);
     return(configuration);
 }
 /// <summary>
 /// Add endpoint, mapped by function
 /// </summary>
 public static ServiceBusConfiguration AddEndpoint(this ServiceBusConfiguration configuration, Func <Type, Boolean> typeChecker, String queueName, ITransport transport = null)
 {
     configuration.EndpointsMapping.Map(typeChecker, queueName, transport);
     return(configuration);
 }
 /// <summary>
 /// Add endpoint mapped by type full name
 /// </summary>
 public static ServiceBusConfiguration AddEndpoint(this ServiceBusConfiguration configuration, String typeWildcard, String queueName, ITransport transport = null)
 {
     configuration.EndpointsMapping.Map(type => type.FullName.StartsWith(typeWildcard), queueName, transport);
     return(configuration);
 }
 /// <summary>
 /// Name of instance of ServiceBus. Used for logging.
 /// </summary>
 public static ServiceBusConfiguration SetName(this ServiceBusConfiguration configuration, string name)
 {
     configuration.Name = name;
     return(configuration);
 }
 public static ServiceBusConfiguration Out(this ServiceBusConfiguration configuration, out ServiceBusConfiguration outConfiguration)
 {
     outConfiguration = configuration;
     return(configuration);
 }
 public static ServiceBusConfiguration Modify(this ServiceBusConfiguration configuration, Action <ServiceBusConfiguration> action)
 {
     action(configuration);
     return(configuration);
 }
 /// <summary>
 /// Set Unity Container
 /// </summary>
 public static ServiceBusConfiguration SetServiceLocator(this ServiceBusConfiguration configuration, IServiceLocator container)
 {
     configuration.ServiceLocator = container;
     return(configuration);
 }