/// <summary>
 /// Добавить получатель сообщения.
 /// </summary>
 /// <typeparam name="TReceiver">Тип получателя.</typeparam>
 /// <param name="serviceCollection">Коллекция сервисов.</param>
 /// <param name="rabbitConfiguration">Конфигурация RabbitMQ.</param>
 public static void AddMessageReceiver <TReceiver>(this IServiceCollection serviceCollection, RabbitConfiguration rabbitConfiguration)
     where TReceiver : class, IHostedService
 {
     serviceCollection.AddMessageReceiver((serviceProvider, scopeFactory) => (TReceiver)Activator.CreateInstance(typeof(TReceiver), rabbitConfiguration, scopeFactory, serviceProvider.GetService <ILogger <TReceiver> >()));
 }
예제 #2
0
 public ExposedRabbitService(RabbitConfiguration config) : base(config)
 {
 }
예제 #3
0
 public Rabbit(RabbitConfiguration rabbitConfiguration)
 {
     this.RabbitConfiguration = rabbitConfiguration;
 }
예제 #4
0
 //default behaviour of queue service.
 public virtual IQueueService CreateQueue(RabbitConfiguration config)
 {
     return(new QueueService(config, _provider.GetService <ILogger <QueueService> >()));
 }
예제 #5
0
 public RabbitConsumer(IOptionsMonitor <RabbitConfiguration> rabbitConfigurationOptions, IServiceProvider serviceProvider)
 {
     this.rabbitConfiguration = rabbitConfigurationOptions.CurrentValue;
     this.serviceProvider     = serviceProvider;
 }
예제 #6
0
 public static IBusConfigurator UseRabbitMQTransport(this IBusConfigurator busConfigurator,
                                                     RabbitConfiguration config) => UseRabbitMQTransport(busConfigurator, config, null);
예제 #7
0
 public StubQueueService(RabbitConfiguration config)
 {
     RabbitConfig = config;
 }
예제 #8
0
 public DataPointPublisher(IOptionsMonitor <RabbitConfiguration> rabbitConfigurationOptions)
 {
     this.rabbitConfiguration = rabbitConfigurationOptions.CurrentValue;
 }
예제 #9
0
 public ExposedQueueService(ILogger <QueueService> logger, RabbitConfiguration rabbitConfig) : base(rabbitConfig, logger)
 {
     Consumer = new ExposedConsumer {
         Model = ExposedChannel
     };
 }
예제 #10
0
        /// <summary>
        /// Конфигурирует все сервисы приложения.
        /// </summary>
        /// <param name="services">Коллекция сервисов.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            ValidatorOptions.LanguageManager.Enabled = false;

            services.AddCors(options =>
            {
                options.AddPolicy(CorsPolicyName,
                                  builder => builder
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials()
                                  .SetIsOriginAllowed(x => true));
            });

            services.Configure <MongoSettings>(Configuration.GetSection(nameof(MongoSettings)).Bind);
            services.Configure <EmailSettings>(Configuration.GetSection(nameof(EmailSettings)).Bind);

            services.AddSingleton <MongoContext>();
            services.AddSingleton <IMessageTemplatesRepository, MessageTemplatesRepository>();
            services.AddSingleton <ITemplateManager, TemplateManager>();

            services.AddControllers();

            services.AddAuthentication();
            services.AddAuthorization();

            services.AddMvcCore(options => options.Filters.Add(typeof(FormatResponseFilter)))
            .AddNewtonsoftJson()
            .AddApiExplorer()
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>());

            services.AddScoped <JinjaTemplateEngine>();
            services.AddScoped <RazorTemplateEngine>();

            services.AddScoped <IEmailBodyGenerator, EmailBodyGenerator>();

            var rabbitConfiguration = new RabbitConfiguration();

            Configuration.GetSection(nameof(RabbitConfiguration)).Bind(rabbitConfiguration);

            services.AddMessageReceiver <RabbitMessageReceiver <NotificationMessage <EmailNotificationMessage>, EmailNotificationHandler> >(rabbitConfiguration);

            services.Configure <AuthorizationSettings>(Configuration.GetSection(nameof(AuthorizationSettings)).Bind);
            services.AddScoped <IAsyncAuthorizationFilter, JWTAuthorizationFilterAttribute>();
            services.AddScoped <IEmailMessageFactory, EmailMessageFactory>();
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Notification Service", Version = "v1"
                });
                options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Bearer token\"",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey
                });

                options.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference {
                                Type = ReferenceType.SecurityScheme, Id = "Bearer"
                            }
                        },
                        new List <string>()
                    }
                });

                string xmlCommentsPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
                options.IncludeXmlComments(xmlCommentsPath);
            });

            services.AddFluentEmail(Configuration.GetSection(nameof(SmtpClientSettings)).Get <SmtpClientSettings>());
            services.Configure <ApiBehaviorOptions>(o => o.InvalidModelStateResponseFactory = actionContext =>
                                                                                              new BadRequestObjectResult(actionContext.ModelState).ToFormattedResponse());

            services.AddTransient <IValidator <JwtSecurityToken>, JwtSecurityTokenValidator>();
        }
예제 #11
0
 public ConnectionManager(RabbitConfiguration configuration)
 {
     Configuration = configuration;
 }