// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var restApiConfigSection = Configuration.GetSection("RestApiConfig"); RestApiConfig restApiConfig = restApiConfigSection.Get <RestApiConfig>(); services.AddSingleton(restApiConfig); var blobStorageConfigSection = Configuration.GetSection("BlobStorageConfig"); BlobStorageConfig blobStorageConfig = blobStorageConfigSection.Get <BlobStorageConfig>(); services.AddSingleton(blobStorageConfig); var jwtConfigSection = Configuration.GetSection("JwtSettings"); JWTConfig jWTConfig = jwtConfigSection.Get <JWTConfig>(); jWTConfig.CreateSecurityKey(); services.AddSingleton(jWTConfig); // https://code-maze.com/create-pdf-dotnetcore/ services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/http-requests?view=aspnetcore-3.1#basic-usage services.AddHttpClient(); services.AddScoped <ServiceRepository>(); services.AddDbContext <FrontEndContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DbConnectionString"))); services.AddDefaultIdentity <FrontEndUser>(options => options.SignIn.RequireConfirmedAccount = false) .AddRoles <IdentityRole>() .AddEntityFrameworkStores <FrontEndContext>(); services.AddRazorPages(); services.AddControllersWithViews(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var jwtConfigSection = Configuration.GetSection("JwtSettings"); JWTConfig jWTConfig = jwtConfigSection.Get <JWTConfig>(); jWTConfig.CreateSecurityKey(); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ClockSkew = TimeSpan.FromMinutes(5), IssuerSigningKey = jWTConfig.SecurityKey, RequireSignedTokens = true, RequireExpirationTime = true, ValidateLifetime = true, ValidateIssuer = true, ValidIssuer = jWTConfig.Issuer, ValidateAudience = true, ValidAudience = jWTConfig.Audience }; }); services.AddDbContext <BackEndContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("DbConnectionString")); }); services.AddControllers(); }