// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); var mapper = AutoMapperConfig.RegisterMappings().CreateMapper(); services.AddSingleton(mapper); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <HttpContext>(p => p.GetService <IHttpContextAccessor>()?.HttpContext); IoCRegister.AddAutoMapperSetup(ref services); services.AddRegistration(); services.AddHttpContextAccessor(); services.AddMvc(options => { options.Filters.Add(typeof(FilterException)); // Si hubiese Inyección de dependencias en el filtro }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2). AddJsonOptions(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = true, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["jwt:key"])), ClockSkew = TimeSpan.Zero }); }