Beispiel #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //Validação dos serviços e injeção das dependencias
            CommonTypesOptions commonTypesOptions = Configuration.GetSection(nameof(CommonTypesOptions)).Get <CommonTypesOptions>();

            if (commonTypesOptions != null)
            {
                foreach (var tipo in commonTypesOptions.GetConfiguracoesServicosTypes())
                {
                    IConfiguracaoServico instancia = (IConfiguracaoServico)Activator.CreateInstance(tipo);
                    instancia.ConfigurarServicos(Configuration, services);
                }
            }
            services.AddSingleton <IConfiguration>(Configuration);
            services.AddSingleton(
                provider =>
            {
                var settings = new JsonSerializerSettings
                {
                    ContractResolver     = new CamelCasePropertyNamesContractResolver(),
                    DateFormatHandling   = DateFormatHandling.IsoDateFormat,
                    DefaultValueHandling = DefaultValueHandling.Include,
                    NullValueHandling    = NullValueHandling.Ignore,
                    DateTimeZoneHandling = DateTimeZoneHandling.Local
                };

                return(settings);
            }
                );

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Version     = "v1",
                    Title       = "Desafio técnico da SoftPlan",
                    Description = "ASP.NET Core Web API - Microserviço para calcular juros compostos",
                    Contact     = new Swashbuckle.AspNetCore.Swagger.Contact
                    {
                        Name  = "SoftPlayer Lucas",
                        Email = "*****@*****.**",
                        Url   = "https://www.linkedin.com/in/lucas-dahne/",
                    },
                    License = new Swashbuckle.AspNetCore.Swagger.License
                    {
                        Name = "GNU General Public License (GNU GPL)",
                        Url  = "https://www.gnu.org/licenses/licenses.pt-br.html",
                    }
                });
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
        }