feat: ajout des options de démarrage pour l’environnement de développement dans les paramètres de lancement

This commit is contained in:
mirage
2026-04-01 10:05:29 +02:00
parent 21e1ab438c
commit afdb94c7d3
2 changed files with 36 additions and 4 deletions

View File

@@ -38,6 +38,7 @@ try
// En fonction de la configuration, utilise soit les repositories basés sur une base de données, soit les repositories basés sur des listes locales. // En fonction de la configuration, utilise soit les repositories basés sur une base de données, soit les repositories basés sur des listes locales.
var repositoryType = builder.Configuration.GetValue<RepositoryType>("Repository"); var repositoryType = builder.Configuration.GetValue<RepositoryType>("Repository");
var seederType = builder.Configuration.GetValue<SeederType>("Seeder"); var seederType = builder.Configuration.GetValue<SeederType>("Seeder");
var shouldSeed = args.Contains("--seed");
if (repositoryType == RepositoryType.Db) if (repositoryType == RepositoryType.Db)
{ {
if (builder.Environment.IsProduction()) if (builder.Environment.IsProduction())
@@ -77,10 +78,21 @@ try
using (var scope = app.Services.CreateScope()) using (var scope = app.Services.CreateScope())
{ {
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>(); var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
db.Database.EnsureDeleted(); if (shouldSeed)
db.Database.EnsureCreated(); {
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>(); db.Database.EnsureDeleted();
repo.SeedBaseDeDonnees(); db.Database.EnsureCreated();
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
if (seederType == SeederType.Local)
{
repo.SeedBaseDeDonnees();
}
else if (seederType == SeederType.Spotify)
{
// Seed à l'aide de l'API Spotify.
}
}
} }
} }
else else

View File

@@ -18,6 +18,26 @@
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
},
"http-seed": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5038",
"commandLineArgs": "--seed",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https-seed": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7095;http://localhost:5038",
"commandLineArgs": "--seed",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
} }
} }
} }