void InitializeIfNecessary()
        {
            if (Interlocked.Exchange(ref initializeSignaled, 1) != 0)
            {
                return;
            }

            Guard.AgainstUnsetSerializerSetting(Settings);

            var sendOnly = Settings.GetOrDefault <bool>("Endpoint.SendOnly");
            var localAddressForSendOnlyEndpoint = ToTransportAddress(LogicalAddress.CreateLocalAddress(Settings.EndpointName(), new Dictionary <string, string>()));

            try
            {
                localAddress = sendOnly ? localAddressForSendOnlyEndpoint : Settings.LocalAddress();
            }
            catch
            {
                // For tests other than Acceptance tests, LocalAddress() will throw
                localAddress = localAddressForSendOnlyEndpoint;
            }

            defaultNamespaceAlias        = Settings.Get <string>(WellKnownConfigurationKeys.Topology.Addressing.DefaultNamespaceAlias);
            namespaceConfigurations      = Settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces);
            messageSizePaddingPercentage = Settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.MessageSizePaddingPercentage);

            var partitioningStrategyType = (Type)Settings.Get(WellKnownConfigurationKeys.Topology.Addressing.Partitioning.Strategy);

            partitioningStrategy = partitioningStrategyType.CreateInstance <INamespacePartitioningStrategy>(Settings);

            namespaceManager = new NamespaceManagerLifeCycleManagerInternal(new NamespaceManagerCreator(Settings));
            messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(new MessagingFactoryCreator(namespaceManager, Settings), Settings);

            messageReceiverLifeCycleManager = new MessageReceiverLifeCycleManager(new MessageReceiverCreator(messagingFactoryLifeCycleManager, Settings), Settings);
            senderLifeCycleManager          = new MessageSenderLifeCycleManager(new MessageSenderCreator(messagingFactoryLifeCycleManager, Settings), Settings);

            oversizedMessageHandler = (IHandleOversizedBrokeredMessages)Settings.Get(WellKnownConfigurationKeys.Connectivity.MessageSenders.OversizedBrokeredMessageHandlerInstance);

            topologyManager  = CreateTopologySectionManager(defaultNamespaceAlias, namespaceConfigurations, partitioningStrategy, addressingLogic);
            topologyCreator  = new TopologyCreator(CreateSubscriptionCreator(), new AzureServiceBusQueueCreator(TopologySettings.QueueSettings, Settings), new AzureServiceBusTopicCreator(TopologySettings.TopicSettings), namespaceManager, Settings);
            topologyOperator = new TopologyOperator(messageReceiverLifeCycleManager, new BrokeredMessagesToIncomingMessagesConverter(Settings, new DefaultConnectionStringToNamespaceAliasMapper(Settings)), Settings);
        }
        public OutgoingBatchRouter(BatchedOperationsToBrokeredMessagesConverter outgoingMessageConverter, MessageSenderLifeCycleManager sendersLifeCycleManager, ReadOnlySettings settings, IHandleOversizedBrokeredMessages oversizedMessageHandler)
        {
            this.outgoingMessageConverter = outgoingMessageConverter;
            this.sendersLifeCycleManager  = sendersLifeCycleManager;
            this.oversizedMessageHandler  = oversizedMessageHandler;

            sendViaFromConfiguration    = settings.Get <bool>(WellKnownConfigurationKeys.Connectivity.SendViaReceiveQueue);
            transportTypeIsNetMessaging = settings.Get <TransportType>(WellKnownConfigurationKeys.Connectivity.TransportType) == TransportType.NetMessaging;

            backOffTimeOnThrottle        = settings.Get <TimeSpan>(WellKnownConfigurationKeys.Connectivity.MessageSenders.BackOffTimeOnThrottle);
            maxRetryAttemptsOnThrottle   = settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.RetryAttemptsOnThrottle);
            maximuMessageSizeInKilobytes = settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.MaximumMessageSizeInKilobytes);
        }