Exemplo n.º 1
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">IServiceCollection object instance</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services
            .AddControllers(opt => GlobalFilters.Configure(opt))
            .AddDataAnnotationsLocalization(options =>
            {
                options.DataAnnotationLocalizerProvider = (type, factory) =>
                {
                    return(factory.Create(typeof(Resource)));
                };
            })
            .AddJsonOptions(opt =>
            {
                opt.JsonSerializerOptions.IgnoreNullValues = true;
                opt.JsonSerializerOptions.WriteIndented    = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == Environments.Development;
            })
            .ConfigureApiBehaviorOptions(opt => opt.SuppressModelStateInvalidFilter = true);
            services.AddApiVersioning();
            services.AddHttpContextAccessor();
            services.AddCors();
            services.AddResponseCaching();

            var assemblyName = Assembly.GetExecutingAssembly().GetName().Name;

            services.AddJwtToken(Configuration);
            services.AddSwaggerGenerator(Configuration, assemblyName);
            services.AddAuthRegister(Configuration);
            services.AddAppPolicies(Configuration);
            services.AddMiddlewareLoggingOption(Configuration);
            services.AddApplicationHealthChecks(Configuration);
            services.AddScoped <ITokenHelper, TokenHelper>();
            services.AddCultureLanguage(Configuration);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Configuração dos serviços
        /// </summary>
        /// <param name="services">Coleção de serviços</param>
        public void ConfigureServices(IServiceCollection services)
        {
            #region HealthCheck

            services.AddHealthChecks()
            //.AddCheck("Google Ping", new PingHealthCheck("www.google.com", 100))
            //.AddCheck("Bing Ping", new PingHealthCheck("www.bing.com", 100))
            .AddUrlGroup(
                new Uri("https://apps.correios.com.br"),
                name: "Acesso a Apps dos Correios",
                failureStatus: HealthStatus.Degraded)
            .AddMongoDb(
                mongodbConnectionString: Configuration.GetValue <string>("ConnectionStrings:MongoDb"),
                name: "MongoDB",
                failureStatus: HealthStatus.Unhealthy,
                timeout: TimeSpan.FromSeconds(15),
                tags: new string[] { "mongodb" });

            #endregion

            #region Swagger

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1",
                             new OpenApiInfo
                {
                    Title       = "OpenBrasil Endereços",
                    Version     = "v1",
                    Description = "Api de busca de Endereços (CEP & Logradouro)",
                    Contact     = new OpenApiContact
                    {
                        Name = "Rodrigo Rodrigues",
                        Url  = new Uri("https://github.com/rodriguesrm")
                    }
                });

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

            #endregion

            // Serviços de injeção da aplicação
            services.AddApplicationService(Configuration);
            services.AddMiddlewareLoggingOption(Configuration);

            services
            .AddControllers(opt => GlobalFilters.Configure(opt))
            .ConfigureApiBehaviorOptions(opt => opt.SuppressModelStateInvalidFilter = true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// </summary>
        /// <param name="services">Service collection</param>
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services
            .AddControllersWithViews()
            .AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));

            services.AddApplicationSwagger();
            services.AddApplicationService(Configuration);
            services.AddApplicationHealthChecks(Configuration);
            services.AddMiddlewareLoggingOption(Configuration);

            services
            .AddControllers(opt => GlobalFilters.Configure(opt))
            .ConfigureApiBehaviorOptions(opt => opt.SuppressModelStateInvalidFilter = true);
        }