// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews() .AddNewtonsoftJson(x => { x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; x.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new DefaultNamingStrategy() }; }); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); DI.Config(services); /* string conString = Microsoft .Extensions .Configuration .ConfigurationExtensions .GetConnectionString(this.Configuration, "KhInventoryContext");*/ services.AddDbContext<KhInventoryDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("KhInventoryContext"))); //options.UseSqlite("Data Source=(localdb)\\MSSQLLocalDB;Database=KhosrowshahDb")); //options.UseInMemoryDatabase("KhInventoryContext")); //options.UseSqlServer(Configuration.GetConnectionString("KhInventoryContext"))); ; // Register the Swagger services services.AddSwaggerDocument(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <ApplicationDbContext>(o => { // Make sure the identity database is created o.Database.Migrate(); }); services.Configure <CookiePolicyOptions>(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; options.HttpOnly = HttpOnlyPolicy.Always; options.Secure = CookieSecurePolicy.Always; // you can add more options here and they will be applied to all cookies (middleware and manually created cookies) }); /*services.AddDbContext<ApplicationDbContext>(options => * options.UseSqlServer( * Configuration.GetConnectionString("KhInventoryContext")), * ServiceLifetime.Transient);*/ services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false) .AddEntityFrameworkStores <ApplicationDbContext>(); services.AddIdentityServer().AddApiAuthorization <IdentityUser, ApplicationDbContext>(); services.AddAuthentication() .AddCookie(setup => { setup.Cookie.Name = "MyCookie"; setup.SlidingExpiration = false; setup.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest; setup.Cookie.SameSite = SameSiteMode.None; }) .AddIdentityServerJwt(); services.AddControllersWithViews() .AddNewtonsoftJson(x => { x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; x.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new DefaultNamingStrategy() }; }).AddRazorRuntimeCompilation(); services.AddRazorPages(); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); DI.Config(services); services.AddDbContext <KhInventoryDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("KhInventoryContext"))); services.Configure <IdentityOptions>(options => { // Default Password settings. options.Password.RequireDigit = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequiredLength = 6; options.Password.RequiredUniqueChars = 0; }); }