public static void ConfigurarDependencias(IConfiguration configuration, IServiceCollection services, bool singleton = false) { RegistraDependencias.Registrar(services, configuration, singleton); Orquestrador.Inicializar(services.BuildServiceProvider()); Orquestrador.Registrar(new Processor(configuration, "ADSync-HangFire-SqlServer")); RegistrarServicosRecorrentes.Registrar(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddHttpContextAccessor(); RegistraDependencias.Registrar(services); RegistrarHttpClients(services, configuration); services.AddApplicationInsightsTelemetry(configuration); var provider = services.BuildServiceProvider(); //services.AdicionarRedis(configuration, provider.GetService<IServicoLog>()); if (env.EnvironmentName != "teste-integrado") { services.AddRabbit(); } services.AddHostedService <WorkerRabbitMQ>(); // Teste para injeção do client de telemetria em classe estática var serviceProvider = services.BuildServiceProvider(); var clientTelemetry = serviceProvider.GetService <TelemetryClient>(); DapperExtensionMethods.Init(clientTelemetry); SentrySdk.Init(configuration.GetValue <string>("Sentry:DSN")); services.AddMemoryCache(); }
// 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(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { RegistraDependencias.ConfiguraServicos(services, Configuration); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "DasaLaboratoriosAPI", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); RegistraDependencias.Registrar(services); services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; }); services.AddMvc(options => { options.AllowValidatingTopLevelNodes = false; options.EnableEndpointRouting = true; options.Filters.Add(new ValidaDtoAttribute()); options.Filters.Add(new FiltroExcecoes()); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "SGP v1", Version = "v1" }); }); }
public void ConfigureServices(IServiceCollection services) { services.AddSingleton(Configuration); services.Configure <ApiBehaviorOptions>(options => { options.SuppressModelStateInvalidFilter = true; }); services.AddMvc(c => { c.AllowValidatingTopLevelNodes = false; c.EnableEndpointRouting = true; c.Filters.Add(new ValidarDtoAttribute()); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddJsonOptions(options => { options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; }); var connectionString = Configuration.GetConnectionString("DefaultConnection"); services.AddDbContext <ContextoTarefa>(options => options.UseSqlServer(connectionString)); RegistraDependencias.Registrar(services); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Gestão de tarefas", Version = "v1", Description = "Sistema para gerenciamento de tarefas." }); }); }
// 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"); }); }
// 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") }; }); }
// 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(); }