source: Application/ocrent/Program.cs

Last change on this file was f5f7c24, checked in by 192011 <mk.snicker@…>, 17 months ago

Initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1using Microsoft.AspNetCore.Identity;
2using Models.DatabaseModels;
3using Microsoft.EntityFrameworkCore;
4using Microsoft.AspNetCore.Authentication.Cookies;
5using Dal.ApplicationStorage;
6using Microsoft.Extensions.DependencyInjection.Extensions;
7using Dal.ApplicationStorage.DataAccess.Abstract;
8using Dal.ApplicationStorage.DataAccess.Concrete;
9using Microsoft.AspNetCore.Mvc;
10using Microsoft.Extensions.Options;
11
12var builder = WebApplication.CreateBuilder(args);
13
14
15
16// Add services to the container.
17builder.Services.AddControllersWithViews(opt => opt.Filters.Add(new AutoValidateAntiforgeryTokenAttribute()));
18
19// Data Access scoped
20builder.Services.TryAddScoped<IIdentityCustomDa, IdentityDa>();
21builder.Services.TryAddScoped<ISearchDa, SearchDa>();
22builder.Services.TryAddScoped<ICompanyDa, CompanyDa>();
23builder.Services.TryAddScoped<IAdministrator, AdministratorDa>();
24
25
26builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
27builder.Services.AddSession();
28builder.Services.AddSession(options => {
29 options.IdleTimeout = TimeSpan.FromMinutes(30);
30});
31
32builder.Services.AddEntityFrameworkNpgsql().AddDbContext<ApiContext>();
33
34builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
35 .AddCookie(options =>
36 {
37 options.ExpireTimeSpan = TimeSpan.FromMinutes(20);
38 options.SlidingExpiration = true;
39 options.AccessDeniedPath = "/Forbidden/";
40 });
41
42
43var app = builder.Build();
44
45// Configure the HTTP request pipeline.
46if (!app.Environment.IsDevelopment())
47{
48 app.UseExceptionHandler("/Home/Error");
49 // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
50 app.UseHsts();
51}
52
53app.UseCookiePolicy();
54app.UseHttpsRedirection();
55app.UseStaticFiles();
56app.UseSession();
57
58app.UseRouting();
59app.UseAuthentication();
60
61app.UseAuthorization();
62
63app.MapControllerRoute(
64 name: "default",
65 pattern: "{controller=Home}/{action=Index}/{id?}");
66
67app.Run();
Note: See TracBrowser for help on using the repository browser.