// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpContextAccessor();
            ConfiguraVariaveisAmbiente(services);

            RegistraDependencias.Registrar(services, Configuration);

            RegistrarHttpClients(services, Configuration);

            services.AddRabbit(RabbitOptions);
            services.AddPolicies();
            services.AddHostedService <WorkerRabbitMQ>();

            ConfiguraRabbitParaLogs(services);

            var telemetriaOptions = ConfiguraTelemetria(services);
            var servicoTelemetria = new ServicoTelemetria(telemetriaOptions);

            DapperExtensionMethods.Init(servicoTelemetria);
            services.AddSingleton(servicoTelemetria);

            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                //c.AddServer(new OpenApiServer() { Description = "Dev", Url = "https://dev-gcasync.sme.prefeitura.sp.gov.br" });
                //TODO: Remover rota fixa

                c.SwaggerDoc("v1",
                             new OpenApiInfo
                {
                    Title       = "SME.GoogleClassroom.Worker.Rabbit",
                    Description = "Serviço de integração EOL com o Google Classroom",
                    Version     = "v1"
                });
                c.OperationFilter <AdicionaCabecalhoHttp>();

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });

            var serviceProvider = services.BuildServiceProvider();
            var mediator        = serviceProvider.GetService <IMediator>();

            services.AddSingleton(mediator);

            services.AddMvc(options =>
            {
                options.EnableEndpointRouting = true;
                options.Filters.Add(new FiltroExcecoesAttribute(mediator));
            });

            services.UseMetricReporter();
        }
        public WorkerRabbitMQ(IConnection conexaoRabbit,
                              IServiceScopeFactory serviceScopeFactory,
                              IMetricReporter metricReporter,
                              ServicoTelemetria servicoTelemetria,
                              ConsumoDeFilasOptions consumoDeFilasOptions,
                              ConfiguracaoRabbitOptions configuracaoRabbitOptions,
                              TelemetriaOptions telemetriaOptions,
                              IMediator mediator)
        {
            this.conexaoRabbit             = conexaoRabbit ?? throw new ArgumentNullException(nameof(conexaoRabbit));
            this.serviceScopeFactory       = serviceScopeFactory ?? throw new ArgumentNullException(nameof(serviceScopeFactory));
            this.telemetriaOptions         = telemetriaOptions ?? throw new ArgumentNullException(nameof(telemetriaOptions));
            this.mediator                  = mediator ?? throw new ArgumentNullException(nameof(mediator));
            this.metricReporter            = metricReporter;
            this.servicoTelemetria         = servicoTelemetria ?? throw new ArgumentNullException(nameof(servicoTelemetria));
            this.consumoDeFilasOptions     = consumoDeFilasOptions ?? throw new ArgumentNullException(nameof(consumoDeFilasOptions));
            this.configuracaoRabbitOptions = configuracaoRabbitOptions ?? throw new ArgumentNullException(nameof(configuracaoRabbitOptions));

            comandos = new Dictionary <string, ComandoRabbit>();
            RegistrarUseCases();
        }
 public static void Init(ServicoTelemetria servicoTelemetriaSgp)
 {
     servicoTelemetria = servicoTelemetriaSgp;
 }
 public SalvarLogViaRabbitCommandHandler(ConfiguracaoRabbitLogOptions configuracaoRabbitOptions, ServicoTelemetria servicoTelemetria)
 {
     this.configuracaoRabbitOptions = configuracaoRabbitOptions ?? throw new System.ArgumentNullException(nameof(configuracaoRabbitOptions));
     this.servicoTelemetria         = servicoTelemetria ?? throw new System.ArgumentNullException(nameof(servicoTelemetria));
 }