-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (49 loc) · 2.11 KB
/
Program.cs
File metadata and controls
62 lines (49 loc) · 2.11 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
using Gridly.Configuration;
using Gridly.EndPoints;
using Gridly.Repositories;
using Gridly.Services;
using Gridly.Data;
using Microsoft.Data.Sqlite;
using Microsoft.Extensions.FileProviders;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddControllers();
await builder.Services.AddTokenBucketRateLimiter();
builder.Services.AddScoped<DbInitializer>();
builder.Services.AddScoped<System.Data.IDbConnection>(sp =>
new SqliteConnection(builder.Configuration.GetConnectionString("GridlyDb")));
builder.Services.AddScoped<IVersionEndPoint, VersionEndPoint>();
builder.Services.AddScoped<IComponentRepository,ComponentRepository>();
builder.Services.AddScoped<IComponentSettingsRepository,ComponentSettingsRepository>();
builder.Services.AddScoped<IIconRepository,IconRepository>();
builder.Services.AddScoped<IIconConnectedRepository,IconConnectedRepository>();
builder.Services.AddSingleton<IMemoryCashingService, MemoryCashingServices>();
builder.Services.AddSingleton<IHttpClientServices, HttpClientServices>();
builder.Services.AddSingleton<IFileService, FileService>();
builder.Services.AddSingleton(typeof(IDataConverter<>), typeof(DataConverter<>));
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssemblies(AppDomain.CurrentDomain.GetAssemblies()));
var app = builder.Build();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "Assets/Icons")),
RequestPath = "/Assets/Icons"
});
app.MapDefaultControllerRoute().RequireRateLimiting("fixed");
app.MapControllerRoute(
name: "default",
pattern: "{controller=Main}/{action=Index}");
app.UseRouting();
app.UseTokenBucketRateLimiter();
using (var scope = app.Services.CreateScope())
{
var dbInit = scope.ServiceProvider.GetRequiredService<DbInitializer>();
await dbInit.EnsureTablesCreatedAsync();
}
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
app.Run();