public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddDbContext <CustomerHubDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new DtoToDomainProfile()); cfg.AddProfile(new DomainToDtoProfile()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = "CustomerHub", ValidAudience = "CustomerHub", IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["SecurityKey"])) }; options.Events = new JwtBearerEvents { OnAuthenticationFailed = context => { Console.WriteLine($"Invalid Token: {context.Exception.Message}"); return(Task.CompletedTask); }, OnTokenValidated = context => { Console.WriteLine($"Token OK: {context.SecurityToken}"); return(Task.CompletedTask); } }; }); services.AddOData(); IocService.Register(services); }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <TasklistDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddOData(); services.AddControllers(mvcOptions => mvcOptions.EnableEndpointRouting = false); services.AddMvc().AddFluentValidation(); IocService.Register(services); IocDomain.Register(services); ConfigureMappingService(services); ConfigureAuthenticationService(services); ConfigureSwaggerService(services); }