This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
98 lines (84 loc) · 3.2 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using BioKudi.Models;
using BioKudi.Repository;
using BioKudi.Services;
using BioKudi.Utilities;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.DotNet.Scaffolding.Shared;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.FileProviders;
using Wkhtmltopdf.NetCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container. Dependency
builder.Services.AddDbContext<BiokudiDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("AZURE_SQL_CONNECTIONSTRING")));
builder.Services.AddControllersWithViews();
builder.Services.AddHttpContextAccessor();
builder.Services.AddAuthorization();
builder.Services.AddLogging();
builder.Services.AddRazorPages();
builder.Services.AddScoped<PasswordUtility>();
builder.Services.AddScoped<EmailUtility>();
builder.Services.AddScoped<UserRepository>();
builder.Services.AddScoped<ActivityRepository>();
builder.Services.AddScoped<RoleRepository>();
builder.Services.AddScoped<StateRepository>();
builder.Services.AddScoped<PlaceRepository>();
builder.Services.AddScoped<PictureRepository>();
builder.Services.AddScoped<AuditRepository>();
builder.Services.AddScoped<TicketRepository>();
builder.Services.AddScoped<ReviewRepository>();
builder.Services.AddScoped<UserService>();
builder.Services.AddScoped<ActivityService>();
builder.Services.AddScoped<PlacesService>();
builder.Services.AddScoped<PictureService>();
builder.Services.AddScoped<MapService>();
builder.Services.AddScoped<AuditService>();
builder.Services.AddScoped<StateService>();
builder.Services.AddScoped<RoleService>();
builder.Services.AddScoped<TicketService>();
builder.Services.AddScoped<ReviewService>();
builder.Services.AddHsts(options =>
{
options.Preload = true;
options.IncludeSubDomains = true;
options.MaxAge = TimeSpan.FromDays(60);
});
builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(option =>
{
option.LoginPath = "/Home/Login";
option.AccessDeniedPath = "/Home/AccessDenied";
option.Cookie.HttpOnly = true;
option.Cookie.SameSite = SameSiteMode.Strict;
option.Cookie.IsEssential = true;
option.Cookie.SecurePolicy = CookieSecurePolicy.Always;
});
var wkhtmltopdfPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Rotativa");
builder.Services.AddWkhtmltopdf(wkhtmltopdfPath);
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
else app.UseDeveloperExceptionPage();
app.UseStatusCodePagesWithReExecute("/Home/Error", "?statusCode={0}");
app.UseHttpsRedirection();
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".geojson"] = "application/geo+json";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();