コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(Configuration);
            services.AddHttpContextAccessor();

            RegistraDependencias.Registrar(services);
            RegistrarMapeamentos.Registrar();
            RegistraClientesHttp.Registrar(services, Configuration);
            RegistraAutenticacao.Registrar(services, Configuration);
            RegistrarMvc.Registrar(services, Configuration);

            DefaultTypeMap.MatchNamesWithUnderscores = true;

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "SGP v1", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer",
                                        new ApiKeyScheme
                {
                    In          = "header",
                    Description = "Para autenticação, incluir 'Bearer' seguido do token JWT",
                    Name        = "Authorization",
                    Type        = "apiKey"
                });
                c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > {
                    { "Bearer", Enumerable.Empty <string>() },
                });
            });

            services.AddDistributedRedisCache(options =>
            {
                options.Configuration = Configuration.GetConnectionString("SGP-Redis");
                options.InstanceName  = Configuration.GetValue <string>("Nome-Instancia-Redis");
            });
        }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(Configuration);
            services.AddHttpContextAccessor();

            RegistraDependencias.Registrar(services);
            RegistrarMapeamentos.Registrar();
            RegistraClientesHttp.Registrar(services, Configuration);
            RegistraAutenticacao.Registrar(services, Configuration);
            RegistrarMvc.Registrar(services, Configuration);

            DefaultTypeMap.MatchNamesWithUnderscores = true;

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "SGP v1", Version = "v1"
                });
                c.AddSecurityDefinition("Bearer",
                                        new ApiKeyScheme
                {
                    In          = "header",
                    Description = "Para autenticação, incluir 'Bearer' seguido do token JWT",
                    Name        = "Authorization",
                    Type        = "apiKey"
                });
                c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > {
                    { "Bearer", Enumerable.Empty <string>() },
                });
            });

            services.AddDistributedRedisCache(options =>
            {
                options.Configuration = Configuration.GetConnectionString("SGP-Redis");
                options.InstanceName  = Configuration.GetValue <string>("Nome-Instancia-Redis");
            });

            services.AddApplicationInsightsTelemetry(Configuration);

            Orquestrador.Inicializar(services.BuildServiceProvider());

            if (Configuration.GetValue <bool>("FF_BackgroundEnabled", false))
            {
                Orquestrador.Registrar(new Processor(Configuration, "SGP-Postgres"));
                RegistraServicosRecorrentes.Registrar();
            }
            else
            {
                Orquestrador.Desativar();
            }

            services.AddHealthChecks()
            .AddRedis(
                Configuration.GetConnectionString("SGP-Redis"),
                "Redis Cache",
                null,
                tags: new string[] { "db", "redis" })
            .AddNpgSql(
                Configuration.GetConnectionString("SGP-Postgres"),
                name: "Postgres")
            .AddCheck <ApiJuremaCheck>("API Jurema")
            .AddCheck <ApiEolCheck>("API EOL");

            services.Configure <RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("pt-BR");
                options.SupportedCultures     = new List <CultureInfo> {
                    new CultureInfo("pt-BR"), new CultureInfo("pt-BR")
                };
            });
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: eliton-amcom/SME-NovoSGP
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCompression();

            var configTamanhoLimiteRequest = Configuration.GetSection("SGP_MaxRequestSizeBody").Value ?? "104857600";

            services.Configure <Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(options =>
            {
                options.Limits.MaxRequestBodySize = long.Parse(configTamanhoLimiteRequest);
            });

            services.Configure <BrotliCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Fastest;
            });

            services.AddSingleton(Configuration);
            services.AddHttpContextAccessor();

            RegistraDependencias.Registrar(services);
            RegistraClientesHttp.Registrar(services, Configuration);
            RegistraAutenticacao.Registrar(services, Configuration);
            RegistrarMvc.Registrar(services, Configuration);
            RegistraDocumentacaoSwagger.Registrar(services);

            DefaultTypeMap.MatchNamesWithUnderscores = true;

            services.AddApplicationInsightsTelemetry(Configuration);

            var serviceProvider = services.BuildServiceProvider();

            Orquestrador.Inicializar(serviceProvider);



            //services.AdicionarRedis(Configuration, serviceProvider.GetService<IServicoLog>());

            if (Configuration.GetValue <bool>("FF_BackgroundEnabled", false))
            {
                Orquestrador.Registrar(new Processor(Configuration, "SGP_Postgres"));
                RegistraServicosRecorrentes.Registrar();
            }
            else
            {
                Orquestrador.Desativar();
            }

            services.AddHealthChecks()
            //.AddRedis(
            //     Configuration.GetConnectionString("SGP_Redis"),
            //     "Redis Cache",
            //     null,
            //     tags: new string[] { "db", "redis" })
            .AddNpgSql(
                Configuration.GetConnectionString("SGP_Postgres"),
                name: "Postgres")
            .AddCheck <ApiJuremaCheck>("API Jurema")
            .AddCheck <ApiEolCheck>("API EOL");

            services.Configure <RequestLocalizationOptions>(options =>
            {
                options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("pt-BR");
                options.SupportedCultures     = new List <CultureInfo> {
                    new CultureInfo("pt-BR"), new CultureInfo("pt-BR")
                };
            });

            if (_env.EnvironmentName != "teste-integrado")
            {
                services.AddRabbit();
            }

            // Teste para injeção do client de telemetria em classe estática


            var clientTelemetry = serviceProvider.GetService <TelemetryClient>();

            DapperExtensionMethods.Init(clientTelemetry);

            //

            services.AddMemoryCache();
        }