| [dfe03b8] | 1 | using Microsoft.AspNetCore.Authentication.Cookies;
|
|---|
| 2 | using Microsoft.EntityFrameworkCore;
|
|---|
| 3 | using StockMaster.Data;
|
|---|
| 4 | using StockMaster.Services;
|
|---|
| 5 |
|
|---|
| 6 | var builder = WebApplication.CreateBuilder(args);
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
|---|
| 10 | builder.Services.AddHttpContextAccessor();
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 | builder.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 |
|
|---|
| 22 | builder.Services.AddControllersWithViews();
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | builder.Services.AddHttpContextAccessor();
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | builder.Services.AddDbContext<StockDbContext>(options =>
|
|---|
| 29 | options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | builder.Services.AddSession(options =>
|
|---|
| 33 | {
|
|---|
| 34 | options.IdleTimeout = TimeSpan.FromMinutes(30);
|
|---|
| 35 | options.Cookie.HttpOnly = true;
|
|---|
| 36 | options.Cookie.IsEssential = true;
|
|---|
| 37 | });
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | builder.Services.AddScoped<IAuthService, AuthService>();
|
|---|
| 41 | builder.Services.AddScoped<IProductService, ProductService>();
|
|---|
| 42 | builder.Services.AddScoped<ISaleService, SaleService>();
|
|---|
| 43 | builder.Services.AddScoped<IPurchaseOrderService, PurchaseOrderService>();
|
|---|
| 44 | builder.Services.AddScoped<IWarehouseService, WarehouseService>();
|
|---|
| 45 | builder.Services.AddScoped<IReportService, ReportService>();
|
|---|
| 46 |
|
|---|
| 47 | var app = builder.Build();
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 | if (!app.Environment.IsDevelopment())
|
|---|
| 51 | {
|
|---|
| 52 | app.UseExceptionHandler("/Home/Error");
|
|---|
| 53 | app.UseHsts();
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | app.UseHttpsRedirection();
|
|---|
| 57 | app.UseStaticFiles();
|
|---|
| 58 |
|
|---|
| 59 | app.UseRouting();
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | app.UseSession();
|
|---|
| 63 | app.UseAuthentication();
|
|---|
| 64 | app.UseAuthorization();
|
|---|
| 65 |
|
|---|
| 66 |
|
|---|
| 67 | app.MapControllerRoute(
|
|---|
| 68 | name: "default",
|
|---|
| 69 | pattern: "{controller=Account}/{action=Login}/{id?}");
|
|---|
| 70 |
|
|---|
| 71 | app.Run(); |
|---|