-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
66 lines (53 loc) · 1.99 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
using Servindustria.Data;
using Servindustria.Data.Interfaces;
using Servindustria.Data.Components;
using Serilog;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddDbContext<ServindustriaDBContext>(opt => opt.UseSqlServer(builder.Configuration.GetConnectionString("ServindustriaDBContext")));
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<IAdminCallRequestRepository, AdminCallRequestRepository>();
builder.Services.AddScoped<IAdminContactFormRepository, AdminContactFormRepository>();
builder.Services.AddScoped<IProductRepository, ProductRepository>();
builder.Services.AddScoped<ITechnicalTableOrCatalogRepository, TechnicalTableOrCatalogRepository>();
builder.Services.AddScoped<IProductCategoryRepository, ProductCategoryRepository>();
builder.Services.AddAuthentication("AuthCookies")
.AddCookie("AuthCookies", options =>
{
options.ExpireTimeSpan = TimeSpan.FromMinutes(30);
options.SlidingExpiration = true;
});
Log.Logger = new LoggerConfiguration()
.Enrich
.FromLogContext()
.WriteTo.Console()
.WriteTo.File("logs/Servindustria_Log_.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
builder.Logging.ClearProviders();
builder.Logging.AddSerilog();
var app = builder.Build();
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404)
{
context.Response.Redirect("/", permanent: false);
}
});
using (var scope = app.Services.CreateScope())
{
var context = scope.ServiceProvider.GetRequiredService<ServindustriaDBContext>();
context.Database.EnsureCreated();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseRouting();
app.MapRazorPages();
if (!Directory.Exists("wwwroot/pdfs"))
{
Directory.CreateDirectory("wwwroot/pdfs");
}
app.Run();