40 lines
No EOL
1,021 B
C#
40 lines
No EOL
1,021 B
C#
using FreeTubeSync;
|
|
using FreeTubeSync.Database;
|
|
using FreeTubeSync.EndPoints;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
builder.Services.AddDbContext<DataContext>(options =>
|
|
options.UseSqlite(builder.Configuration.GetConnectionString("FreeTubeSync")));
|
|
|
|
builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
|
|
|
|
// Add services to the container.
|
|
|
|
var app = builder.Build();
|
|
|
|
app.MapHistoryEndpoints();
|
|
app.MapPlaylistEndpoints();
|
|
app.MapProfileEndpoints();
|
|
app.MapSearchHistoryEndpoints();
|
|
app.MapSettingEndpoints();
|
|
app.MapPingEndpoints();
|
|
|
|
await using(var serviceScope = app.Services.CreateAsyncScope())
|
|
await using (var dbContext = serviceScope.ServiceProvider.GetRequiredService<DataContext>())
|
|
{
|
|
try
|
|
{
|
|
await dbContext.Database.MigrateAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
await dbContext.Database.EnsureCreatedAsync();
|
|
}
|
|
}
|
|
|
|
app.Run(); |