/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { //MVC e Fluent Validation services .AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>()); //Swagger services.AddSwaggerGen(c => { c.SwaggerDoc(Configuration["SwaggerVersion"].ToString(), new Info { Title = Configuration["SwaggerTitle"].ToString(), Version = Configuration["SwaggerVersion"].ToString(), Description = Configuration["SwaggerDescription"].ToString(), TermsOfService = "None", Contact = new Contact { Name = Configuration["SwaggerContactName"].ToString(), Email = Configuration["SwaggerContactEmail"].ToString(), Url = Configuration["SwaggerContactUrl"].ToString() } }); // Set the comments path for the Swagger JSON and UI. var xmlMainPath = Path.Combine(AppContext.BaseDirectory, "Wevo.Api.xml"); var xmlAppPath = Path.Combine(AppContext.BaseDirectory, "Wevo.AppService.xml"); c.IncludeXmlComments(xmlMainPath); c.IncludeXmlComments(xmlAppPath); }); //Cors services.AddCors(); //Lendo chaves no arquivo de configuracoes services.AddOptions(); services.Configure <KeysConfig>(Configuration); //AutoMapper services.AddAutoMapper(); //Injecao de dependencia nativa var ioc = new InjectorContainer(); services = ioc.ObterScopo(services); services.AddSingleton <IConfiguration>(Configuration); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //Adicionar a compressão ao servico services.AddResponseCompression(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //MVC e Fluent Validation services .AddMvc(options => { options.Filters.Add(new ApiExceptionFilter()); //Tratamento das Exceptions }) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <Startup>()); //Swagger services.AddSwaggerGen(c => { c.SwaggerDoc(Configuration["SwaggerVersion"].ToString(), new Info { Title = Configuration["SwaggerTitle"].ToString(), Version = Configuration["SwaggerVersion"].ToString(), Description = Configuration["SwaggerDescription"].ToString(), TermsOfService = "None", Contact = new Contact { Name = Configuration["SwaggerContactName"].ToString(), Email = Configuration["SwaggerContactEmail"].ToString(), Url = Configuration["SwaggerContactUrl"].ToString() } }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme { Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", In = "header", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "Bearer", Enumerable.Empty <string>() } }); }); //Autenticacao JWT - Json Web Token services.AddAuthentication(options => { options.DefaultAuthenticateScheme = "JwtBearer"; options.DefaultChallengeScheme = "JwtBearer"; }).AddJwtBearer("JwtBearer", options => { var sec = Encoding.UTF8.GetBytes(Configuration["SecretKey"].ToString()); options.TokenValidationParameters = new TokenValidationParameters { ValidateAudience = false, ValidAudience = "The name of audience", ValidateIssuer = false, ValidIssuer = "The name of issuer", ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(sec), ValidateLifetime = true, }; }); //Cors services.AddCors(); //Lendo chaves no arquivo de configuracoes services.AddOptions(); services.Configure <KeysConfig>(Configuration); //AutoMapper services.AddAutoMapper(); //Injecao de dependencia nativa var ioc = new InjectorContainer(); services = ioc.ObterScopo(services); services.AddSingleton <IConfiguration>(Configuration); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); //Adicionar a compressão ao servico services.AddResponseCompression(); }