-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (47 loc) · 1.88 KB
/
Program.cs
File metadata and controls
60 lines (47 loc) · 1.88 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
using JukeBox.Data;
using JukeBox.Endpoints;
using JukeBox.Repository;
using JukeBox.Services;
using Microsoft.Data.Sqlite;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMemoryCache();
builder.Services.AddScoped<DbInitializer>();
builder.Services.AddScoped<System.Data.IDbConnection>(sp =>
new SqliteConnection(builder.Configuration.GetConnectionString("JukeBoxDb")));
builder.Services.AddScoped<IArtistEndPoint, ArtistEndPoint>();
builder.Services.AddScoped<ICoverArtEndPoint, CoverArtEndPoint>();
builder.Services.AddScoped<IArtistRepository, ArtistRepository>();
builder.Services.AddScoped<ICoverArtRepository, CoverArtRepository>();
builder.Services.AddScoped<IArtistInfoRepository, ArtistInfoRepository>();
builder.Services.AddScoped<IAlbumInfoRepository, AlbumInfoRepository>();
builder.Services.AddSingleton<IMemoryCashingService, MemoryCashingService>();
builder.Services.AddSingleton<IRetryPolicyService, RetryPolicyService>();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddConnections();
builder.Services.AddControllers();
builder.Services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssemblies(AppDomain.CurrentDomain.GetAssemblies()));
builder.Services.Configure<ApiSettings>(builder.Configuration.GetSection("ApiSettings"));
builder.Services.AddHttpClient<IArtistEndPoint, ArtistEndPoint>(client =>
{
client.DefaultRequestHeaders.Add("User-Agent", "JukeBoxkeBox");
});
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var dbInit = scope.ServiceProvider.GetRequiredService<DbInitializer>();
await dbInit.EnsureTablesCreatedAsync();
}
app.MapGet("/", context =>
{
context.Response.Redirect("/swagger");
return Task.CompletedTask;
});
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.UseRouting();
app.UseHttpsRedirection();
app.MapControllers();
app.Run();