source: StockMaster/Program.cs

main
Last change on this file was dfe03b8, checked in by Ceyda <ceyda.huseini@…>, 3 days ago

Initialize StockMaster project

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[dfe03b8]1using Microsoft.AspNetCore.Authentication.Cookies;
2using Microsoft.EntityFrameworkCore;
3using StockMaster.Data;
4using StockMaster.Services;
5
6var builder = WebApplication.CreateBuilder(args);
7
8
9AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
10builder.Services.AddHttpContextAccessor();
11
12
13builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
14 .AddCookie(options =>
15 {
16 options.LoginPath = "/Account/Login";
17 options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
18 options.Cookie.Name = "StockMasterAuth";
19 });
20
21
22builder.Services.AddControllersWithViews();
23
24
25builder.Services.AddHttpContextAccessor();
26
27
28builder.Services.AddDbContext<StockDbContext>(options =>
29 options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
30
31
32builder.Services.AddSession(options =>
33{
34 options.IdleTimeout = TimeSpan.FromMinutes(30);
35 options.Cookie.HttpOnly = true;
36 options.Cookie.IsEssential = true;
37});
38
39
40builder.Services.AddScoped<IAuthService, AuthService>();
41builder.Services.AddScoped<IProductService, ProductService>();
42builder.Services.AddScoped<ISaleService, SaleService>();
43builder.Services.AddScoped<IPurchaseOrderService, PurchaseOrderService>();
44builder.Services.AddScoped<IWarehouseService, WarehouseService>();
45builder.Services.AddScoped<IReportService, ReportService>();
46
47var app = builder.Build();
48
49
50if (!app.Environment.IsDevelopment())
51{
52 app.UseExceptionHandler("/Home/Error");
53 app.UseHsts();
54}
55
56app.UseHttpsRedirection();
57app.UseStaticFiles();
58
59app.UseRouting();
60
61
62app.UseSession();
63app.UseAuthentication();
64app.UseAuthorization();
65
66
67app.MapControllerRoute(
68 name: "default",
69 pattern: "{controller=Account}/{action=Login}/{id?}");
70
71app.Run();
Note: See TracBrowser for help on using the repository browser.