public static IServiceCollection AddServiceBus(this IServiceCollection builder, IConfiguration config, string serviceName = null)
        {
            if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
            {
                builder
                .AddSingleton <IMessengerService, QueueMessengerService>((ctx) =>
                {
                    Common.ServiceBus.QueueClient queueClient = new Common.ServiceBus.QueueClient("UseDevelopmentStorage=true");
                    return(new QueueMessengerService(queueClient, serviceName));
                });
            }
            else
            {
                ServiceBusSettings serviceBusSettings = new ServiceBusSettings();

                config.Bind("ServiceBusSettings", serviceBusSettings);

                builder.AddSingleton(serviceBusSettings);

                builder
                .AddSingleton <IMessengerService, MessengerService>((ctx) =>
                {
                    MessageReceiverFactory messageReceiverFactory = new MessageReceiverFactory(serviceBusSettings.ConnectionString);
                    ManagementClient managementClient             = new ManagementClient(serviceBusSettings.ConnectionString);
                    return(new MessengerService(serviceBusSettings, managementClient, messageReceiverFactory, serviceName));
                });
            }

            return(builder);
        }
Exemplo n.º 2
0
        private static IMessengerService AddServiceBus(IConfiguration configuration, string serviceName)
        {
            if (IsDevelopment)
            {
                CalculateFunding.Common.ServiceBus.QueueClient queueClient = new CalculateFunding.Common.ServiceBus.QueueClient("UseDevelopmentStorage=true");
                return(new QueueMessengerService(queueClient, serviceName));
            }
            else
            {
                ServiceBusSettings serviceBusSettings = new ServiceBusSettings();

                configuration.Bind("ServiceBusSettings", serviceBusSettings);

                MessageReceiverFactory messageReceiverFactory = new MessageReceiverFactory(serviceBusSettings.ConnectionString);
                ManagementClient       managementClient       = new ManagementClient(serviceBusSettings.ConnectionString);

                return(new MessengerService(serviceBusSettings, managementClient, messageReceiverFactory, serviceName));
            }
        }
 public MessageReceiverFactoryShould()
 {
     _messageReceiverFactory = new MessageReceiverFactory();
 }