Esempio n. 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext <ApiDbContext>(options =>
                                                 options.UseSqlServer(SegurancaService.Descriptografar(Configuration.GetConnectionString("DefaultConnection"))));

            //services.AddEntityFrameworkNpgsql()
            //    .AddDbContext<CatalogoDbContext>(options =>
            //    options.UseNpgsql(SegurancaService.Descriptografar(Configuration.GetConnectionString("PostgreSQLDBConnection"))));


            services.AddDbContext <KlinikosDbContext>(options =>
                                                      options.UseSqlServer(Configuration.GetConnectionString("KlinikosConnection")));

            services.AddScoped <UserService>();
            services.AddScoped <AccessManager>();

            _signingConfigurations = new SigningConfigurations();
            services.AddSingleton(_signingConfigurations);

            _tokenConfigurations = new TokenConfigurations();
            new ConfigureFromConfigurationOptions <TokenConfigurations>(
                Configuration.GetSection("TokenConfigurations"))
            .Configure(_tokenConfigurations);
            services.AddSingleton(_tokenConfigurations);

            //Aciona a extensão que irá configurar o uso de
            //autenticação e autorização via tokens
            services.AddJwtSecurity(_signingConfigurations, _tokenConfigurations);


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

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