Example #1
0
        public static IMessageQueueBuilder AddMessageQueueAzureStorageQueue(this IServiceCollection services, Action <MessageQueueOptions> options, ServiceLifetime serviceLifetime = ServiceLifetime.Scoped)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            services.Configure(options);
            var messageQueueOptions = new MessageQueueOptions();

            options?.Invoke(messageQueueOptions);

            services.TryAdd(new ServiceDescriptor(typeof(MessageQueueOptions), x => messageQueueOptions, serviceLifetime));
            services.TryAdd(new ServiceDescriptor(typeof(IMessageQueueAzureStorageQueue), typeof(MessageQueueAzureStorageQueue), serviceLifetime));
            services.TryAdd(new ServiceDescriptor(typeof(IMessageQueue), x => x.GetRequiredService <IMessageQueueAzureStorageQueue>(), serviceLifetime));
            services.TryAdd(new ServiceDescriptor(typeof(IMessageQueueInfo), typeof(MessageQueueInfo), serviceLifetime));

            services.TryAdd(new ServiceDescriptor(typeof(CloudQueueClient), serviceProvider =>
            {
                var storageAccount = CloudStorageAccount.Parse(messageQueueOptions.ConnectionString);
                var queueClient    = storageAccount.CreateCloudQueueClient();
                return(queueClient);
            }, serviceLifetime));

            return(new MessageQueueBuilder(services));
        }
Example #2
0
 public MessageQueueAzureStorageQueue(CloudQueueClient queueClient,
                                      MessageQueueOptions options,
                                      IMessageQueueInfo info)
 {
     _queueClient = queueClient;
     _options     = options;
     _info        = info;
 }
Example #3
0
 public MessageQueueInfo(MessageQueueOptions options, IConfiguration configuration)
 {
     _options       = options;
     _configuration = configuration;
 }