// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().AddJsonOptions(o => { o.JsonSerializerOptions.PropertyNamingPolicy = null; o.JsonSerializerOptions.DictionaryKeyPolicy = null; }); AddDbContext(services); services.AddAutoMapper(Assembly.GetExecutingAssembly()); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.SaveToken = true; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Audience"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"])), ClockSkew = TimeSpan.Zero // Override the default clock skew of 5 mins }; services.AddCors(); }); services.AddAuthorization(config => { config.AddPolicy(Policies.Admin, Policies.AdminPolicy()); config.AddPolicy(Policies.AdvancedUser, Policies.AdvancedUserPolicy()); config.AddPolicy(Policies.BasicUser, Policies.BasicUserPolicy()); }); services.AddControllersWithViews(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.RegisterAssemblyPublicNonGenericClasses( AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(d => d.ManifestModule.Name.Equals("WatchmanWeb.dll")) ) .Where(x => x.Name.EndsWith("Repository") || x.Name.EndsWith("Service")) .AsPublicImplementedInterfaces(); services.AddScoped <ISmsService, SmsService>(); services.AddTransient <IDatabaseInitializer, DatabaseInitializer>(); services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); }