Ajout de la base de données SQLite

This commit is contained in:
Loic Masi
2026-03-25 11:23:14 +01:00
parent acf92c271c
commit 4a338592bf
7 changed files with 125 additions and 2 deletions

View File

@@ -0,0 +1 @@
*.sqlite*

View File

@@ -1,5 +1,7 @@
using NLog;
using NLog.Web;
using Microsoft.EntityFrameworkCore;
using Webzine.EntitiesContext;
using Webzine.Repository;
using Webzine.Repository.Contracts;
@@ -21,6 +23,9 @@ try
builder.Services.AddSingleton<ITitreRepository, LocalEntityRepository>();
builder.Services.AddDbContext<WebzineDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection")));
// NLog: Setup NLog for Dependency injection
builder.Logging.ClearProviders();
builder.Host.UseNLog();
@@ -31,6 +36,12 @@ try
// le dossier wwwroot.
app.UseStaticFiles();
using (var scope = app.Services.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
db.Database.EnsureCreated();
}
// Active le middleware permettant le routage des requetes entrantes.
app.UseRouting();

View File

@@ -17,6 +17,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Data\" />
<Folder Include="wwwroot\data\" />
<Folder Include="wwwroot\lib\" />
</ItemGroup>
@@ -24,6 +25,8 @@
<ItemGroup>
<PackageReference Include="Faker.Net" Version="2.0.163" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="10.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.5" />
<PackageReference Include="NLog.Web.AspNetCore" Version="5.*" />
<PackageReference Include="NLog" Version="6.1.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
@@ -33,6 +36,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Webzine.EntitiesContext\Webzine.EntitiesContext.csproj" />
<ProjectReference Include="..\Webzine.Entity\Webzine.Entity.csproj" />
<ProjectReference Include="..\Webzine.Repository\Webzine.Repository.csproj" />
</ItemGroup>

View File

@@ -7,7 +7,10 @@
},
"Webzine": {
"NombreDerniereChronique": 3,
"NombreDeTopTitres" : 3
"NombreDeTopTitres": 3
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=Data/webzine.sqlite"
},
"AllowedHosts": "*"
}