// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql( DataManage.GetConnectionString(Configuration))); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddIdentity <ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true) .AddDefaultUI() .AddDefaultTokenProviders() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddIdentityServer() .AddApiAuthorization <ApplicationUser, ApplicationDbContext>(); services.AddAuthentication() .AddIdentityServerJwt(); services.AddControllersWithViews(); services.AddRazorPages(); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql( DataManage.GetConnectionString(Configuration))); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddIdentity <CustomUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true) .AddDefaultUI() .AddDefaultTokenProviders() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddTransient <IImageService, BasicImageService>(); services.AddTransient <IEmailSender, EmailService>(); services.Configure <MailSettings>(Configuration.GetSection("MailSettings")); services.AddScoped <ICustomRoleService, CustomRoleService>(); services.AddScoped <ICustomProjectService, CustomProjectService>(); services.AddScoped <ICustomHistoryService, CustomHistoryService>(); services.AddScoped <ICustomFileService, CustomFileService>(); services.AddScoped <ICustomNotificationService, CustomNotificationService>(); services.AddScoped <IListDeveloperAndProject, ListDeveloperandProject>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql( DataManage.GetConnectionString(Configuration))); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddIdentity <CustomUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true) .AddDefaultUI() .AddDefaultTokenProviders() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddMvc().AddNewtonsoftJson(); services.AddScoped <IImageService, ImageService>(); services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddScoped <IHttpConnectionFeature, HttpConnectionFeature>(); services.Configure <MailSettings>(Configuration.GetSection("MailSettings")); services.AddScoped <IEmailSender, EmailService>(); services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); services.AddScoped <IUserDetector, UserDetector>(); services.AddScoped <ICreateTemporaryUser, CreateTemporaryUser>(); services.AddScoped <ISlugService, SlugService>(); services.AddScoped <ICanUserComment, CanUserComment>(); }
// This method gets called by the runtime. Use this method to add services to the container. // Data public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseNpgsql( DataManage.GetConnectionString(Configuration))); services.AddDatabaseDeveloperPageExceptionFilter(); //services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) // .AddEntityFrameworkStores<ApplicationDbContext>(); services.AddIdentity <BlogUser, IdentityRole>(options => { options.SignIn.RequireConfirmedAccount = true; options.Password.RequireDigit = true; options.Password.RequireLowercase = true; options.Password.RequireUppercase = true; options.Password.RequiredLength = 8; options.User.RequireUniqueEmail = true; }) .AddDefaultUI() .AddDefaultTokenProviders() .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddTransient <ISlugService, BasicSlugService>(); services.AddTransient <IImageService, BasicImageService>(); services.AddScoped <IJWTTokenGenerator, JWTTokenGenerator>(); services.Configure <MailSettings>(Configuration.GetSection("MailSettings")); services.AddScoped <IEmailSender, EmailService> (); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Lan's Blog", Version = "v1", Description = "This is an API of Duy Lan Le Blog", Contact = new OpenApiContact { Name = "Duy Lan Le", Email = "*****@*****.**", Url = new System.Uri("https://duylanle-portfolio.netlify.app/") } }); }); services.AddCors(options => { options.AddPolicy("DefaultPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddAuthentication().AddJwtBearer(options => { options.RequireHttpsMetadata = false; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Token:Key"])), ValidIssuer = Configuration["Token:Issuer"], ValidateIssuer = true, ValidateAudience = false, }; }) .AddGitHub(options => { options.ClientId = "2393935c67ed0081500a"; options.ClientSecret = "6f3f252be0b3d8d8a541d3ec1f41b6ce7197f281"; options.AccessDeniedPath = "/AccessDeniedPathInfo"; }) .AddGoogle(options => { options.ClientId = "223021765764-q8m69sfjv45ocr2tasbfc3dgb09m9l4f.apps.googleusercontent.com"; options.ClientSecret = "4qmzM3PdQnGBhRgP-fi2-HSE"; options.AccessDeniedPath = "/AccessDeniedPathInfo"; }) .AddFacebook(options => { options.ClientId = "3621053137942975"; options.ClientSecret = "658032181e5ef1cfa2f0b5cf22b0c6cb"; options.AccessDeniedPath = "/AccessDeniedPathInfo"; }) .AddTwitter(options => { options.ConsumerKey = "MUeZFzSIM0kiXc9XLNq16QURi"; options.ConsumerSecret = "e3a0600ca0b68ccbe83a2e1309bb299c86a39cd6"; options.RetrieveUserDetails = true; options.AccessDeniedPath = "/AccessDeniedPathInfo"; }); }