Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddJsonOptions(opt =>
            {
                opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
                opt.JsonSerializerOptions.IgnoreNullValues = true;
            });

            services.AddScoped <ITransferenciaService, TransferenciaService>();

            services.AddSingleton(x =>
            {
                var optionsBuilder = new DbContextOptionsBuilder <BancoContext>();

                optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
                //optionsBuilder.UseSqlServer(Configuration.GetConnectionString("Padrao"));

                var banco = new BancoContext(optionsBuilder.Options);

                banco.Seed();

                return(banco);
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo
                {
                    Version     = "v1",
                    Title       = "Avaliação Situacional",
                    Description = "ASP.NET Core Web API",
                    //TermsOfService = new Uri(""),
                    Contact = new OpenApiContact
                    {
                        Name  = "Liseane Iesbick",
                        Email = "*****@*****.**",
                        //Url = new Uri(""),
                    }
                });

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

            services.AddCors(options =>
            {
                options.AddPolicy("CorsApi", builder => builder
                                  .AllowAnyOrigin()
                                  .AllowAnyHeader()
                                  .AllowAnyMethod());
            });
        }