Example #1
0
 public void ConfigureServices(IServiceCollection services)
 {
     services.Configure <CookiePolicyOptions>(options =>
     {
         options.CheckConsentNeeded    = context => true;
         options.MinimumSameSitePolicy = SameSiteMode.None;
     });
     services.AddSession();
     services.AddAutoMapper(typeof(MappingProfile));
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.AddDbContext <ApplicationDbContext>(options => options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
     RegistrarDependencias.Registrar(services, Configuration);
 }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            RegistrarDependencias.Registrar(services);

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1",
                             new Info
                {
                    Title       = "Robo Marciano",
                    Version     = "v1",
                    Description = "Sistema para movimentação do Robo Marciano."
                });
            });
        }
Example #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCaching();

            services.AddMvc(options =>
            {
                options.AllowValidatingTopLevelNodes = false;
                options.EnableEndpointRouting        = true;
                options.Filters.Add(new FiltroExcecoesAttribute());
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddHttpContextAccessor();
            RegistrarDependencias.Registrar(services);
            RegistraClientesHttp.Registrar(services, Configuration);

            //services.AddRabbit();

            // In production, the React files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/build";
            });

            // Configura��o de inje��o de depend�ncia do SMEContext (Postgres - Npgsql)
            services.AddDbContext <SMEManagementContext>(options =>
                                                         options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));

            // JWT
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["JwtSettings:Issuer"],
                    ValidAudience    = Configuration["JwtSettings:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["JwtSettings:Key"]))
                };
            });

            // CORS (Cross-Origin Requests)
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder
                                  .AllowAnyOrigin() // Ulilizar a fun��o abaixo e comentar essa para definir permiss�o de acesso de determinadas origens, caso contr�rio ser� aceito qualquer origem da requisi��o
                                                    //.WithOrigins("https://mydomain.com", "http://outroendereco.com.br")
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials()
                                  .Build());
            });

            //Insights
            services.AddApplicationInsightsTelemetry(Configuration);

            // Registra o Swagger Generator (OpenAPI)
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("documentation", new Swashbuckle.AspNetCore.Swagger.Info()
                {
                    Title       = "SME.Pedagogico.Gestao.WebApp",
                    Version     = "v1.0.0",
                    Description = "Documenta��o das APIs do SME.Pedagogico.Gestao.WebApp (.NET Core v2.2)",
                });

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

            var config = new AutoMapper.MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Data.DTO.Portugues.GrupoDTO, Gestao.Models.Autoral.Grupo>();
                cfg.CreateMap <Data.DTO.Portugues.OrdemDTO, Gestao.Models.Autoral.Ordem>();
            });
            IMapper mapper = config.CreateMapper();

            services.AddSingleton(mapper);
        }