コード例 #1
0
 public SqsPoolerHostedService(
     AmazonSQSClient amazonSqsClient,
     SqsPoolerConfig config,
     IConsumerResolver consumerResolver,
     ILogger <SqsPoolerHostedService> logger)
 {
     _amazonSqsClient  = amazonSqsClient;
     _config           = config;
     _consumerResolver = consumerResolver;
     _logger           = logger;
 }
コード例 #2
0
        public static IServiceCollection AddSqsPooler(
            this IServiceCollection services, SqsPoolerConfig config, Assembly[] assembliesWithConsumers)
        {
            services.AddSingleton(config);
            services.AddSingleton <IConsumerResolver, ConsumerResolver>();
            services.AddSingleton(x => new AmazonSQSClient(new AmazonSQSConfig
            {
                RegionEndpoint = RegionEndpoint.GetBySystemName(config.Region)
            }));

            services.AddTransient <IHostedService, SqsPoolerHostedService>();

            var types = assembliesWithConsumers.SelectMany(x => x.GetTypes())
                        .Where(x => x.IsClass && typeof(IConsumer).IsAssignableFrom(x))
                        .ToArray();

            foreach (var type in types)
            {
                services.AddSingleton(typeof(IConsumer), type);
            }

            return(services);
        }