-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (96 loc) · 4.1 KB
/
Copy pathProgram.cs
File metadata and controls
111 lines (96 loc) · 4.1 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
using EmptyTest.AppSettings;
using EmptyTest.Data;
using EmptyTest.Entities;
using EmptyTest.Helpers;
using EmptyTest.Repositories;
using EmptyTest.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.EntityFrameworkCore;
using Serilog;
namespace EmptyTest;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog((context, services, opts) =>
{
opts.Enrich.WithMachineName();
opts.Enrich.WithProcessName();
opts.Enrich.WithProcessId();
opts.Enrich.FromLogContext();
opts.Enrich.With(services.GetService<AppNameEnricher>());
opts.WriteTo.Console();
opts.WriteTo.Seq("http://localhost:8081");
//opts.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri(context.Configuration["ElasticSearch:Uri"]))
//{
// AutoRegisterTemplate = true,
// IndexFormat = $"{context.Configuration["AppName"]}-log-{DateTime.UtcNow.ToString("yyyy-MM-hh")}",
// NumberOfShards = 2,
// NumberOfReplicas = 2
//});
//opts.WriteTo.Seq(context.Configuration["Seq:Url"]);
});
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.Limits.MaxRequestBodySize = long.MaxValue;
options.Limits.MaxRequestBufferSize = int.MaxValue;
});
builder.Services.AddTransient<AppNameEnricher>();
builder.Services.AddControllersWithViews();
builder.Services.AddAuthentication(AuthenticationSchemas.Default).AddCookie(AuthenticationSchemas.Default, cfg =>
{
var authenticationSettings = new AuthenticationSettings();
builder.Configuration.GetSection("Authentication").Bind(authenticationSettings);
cfg.ClaimsIssuer = authenticationSettings.Issuer;
cfg.ExpireTimeSpan = TimeSpan.FromDays(authenticationSettings.ExpireDays);
cfg.LoginPath = "/Auth/SignIn";
cfg.LogoutPath = "/Auth/Logout";
cfg.Cookie.HttpOnly = true;
cfg.ReturnUrlParameter = "RedirectUrl";
});
builder.Services.AddAuthorization();
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL"));
});
builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IAccountRepository, AccountRepository>();
builder.Services.AddAutoMapper(typeof(Program).Assembly);
builder.Services.AddScoped<IPasswordHasher<Account>, PasswordHasher<Account>>();
builder.Services.AddScoped<ITutorialService, TutorialService>();
builder.Services.AddScoped<ITutorialRepository, TutorialRepository>();
builder.Services.AddScoped<IUserContextService, UserContextService>();
builder.Services.AddScoped<ISectionRepository, SectionRepository>();
builder.Services.AddScoped<ISectionService, SectionService>();
builder.Services.AddScoped<ITopicRepository, TopicRepository>();
builder.Services.AddScoped<ITopicService, TopicService>();
builder.Services.AddSingleton<IFileSaveSettingsService, FileSaveSettingsService>();
try
{
var app = builder.Build();
app.UseStaticFiles();
app.UseSerilogRequestLogging();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
app.Run();
}
catch (Exception ex)
{
Log.Fatal("Application caught an exception: {ex}", ex);
}
finally
{
Log.Information("Application stopped");
}
}
}