From 98cee6e7f04cbd26d81c039cb9ce064a9ce96317 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 4 Apr 2024 21:40:45 +0200 Subject: [PATCH] =?UTF-8?q?essai=20de=20r=C3=A9parer=20les=20erreurs=20Z?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApi/WebApi/Controllers/FrontController.cs | 26 +++++++----- WebApi/WebApi/Program.cs | 44 ++++++++++++++++---- WebApi/WebApi/WebApi.csproj | 2 + 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/WebApi/WebApi/Controllers/FrontController.cs b/WebApi/WebApi/Controllers/FrontController.cs index a93e596..c8e9c7f 100644 --- a/WebApi/WebApi/Controllers/FrontController.cs +++ b/WebApi/WebApi/Controllers/FrontController.cs @@ -2,6 +2,7 @@ using DbConnectionLibrairie; using DTOs; using EntityManagers; +using ManagerInterfaces; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -30,18 +31,21 @@ namespace WebApi.Controllers private QuestionController questionController; public FrontController( - Unit unit -// MyDbContext dbContext + AdministratorServiceManager administratorServiceManager, + AnswerServiceManager answerServiceManager, + ChapterServiceManager chapterServiceManager, + LobbyServiceManager lobbyServiceManager, + PlayerServiceManager playerServiceManager, + QuestionServiceManager questionServiceManager ){ - this.unity = unit; -/* unity = new Unit( - new AdministratorServiceManager(new AdministratorDataManager(new AdministratorEntityManager(dbContext))), - new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(dbContext))), - new ChapterServiceManager(new ChapterDataManager(new ChapterEntityManager(dbContext))), - new LobbyServiceManager(new LobbyDataManager(new LobbyEntityManager(dbContext))), - new PlayerServiceManager(new PlayerDataManager(new PlayerEntityManager(dbContext))), - new QuestionServiceManager(new QuestionDataManager(new QuestionEntityManager(dbContext))) - );*/ + this.unity = new Unit( + administratorServiceManager, + answerServiceManager, + chapterServiceManager, + lobbyServiceManager, + playerServiceManager, + questionServiceManager + ); administratorController = new AdministratorController(unity); chapterController = new ChapterController(unity); lobbyController = new LobbyController(unity); diff --git a/WebApi/WebApi/Program.cs b/WebApi/WebApi/Program.cs index bed0a30..3005950 100644 --- a/WebApi/WebApi/Program.cs +++ b/WebApi/WebApi/Program.cs @@ -1,7 +1,13 @@ +using DataManagers; using DbConnectionLibrairie; +using DTOs; +using EntityManagers; +using ManagerInterfaces; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using ServiceManagers; +using WebApi; using WebApi.Controllers; var builder = WebApplication.CreateBuilder(args); @@ -14,16 +20,36 @@ builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddApiVersioning(); +var connection = new SqliteConnection("DataSource=database"); +connection.Open(); -builder.Services.AddSingleton(provider => { - var connection = new SqliteConnection("DataSource=database"); - connection.Open(); - - var options = new DbContextOptionsBuilder() - .UseSqlite(connection) - .Options; - - return new MyDbContext(options); +var options = new DbContextOptionsBuilder() +.UseSqlite(connection) +.Options; +var dbContext = new MyDbContext(options); +builder.Services.AddSingleton(provider => +{ + return new AdministratorServiceManager(new AdministratorDataManager(new AdministratorEntityManager(dbContext))); +}); +builder.Services.AddSingleton(provider => +{ + return new AnswerServiceManager(new AnswerDataManager(new AnswerEntityManager(dbContext))); +}); +builder.Services.AddSingleton(provider => +{ + return new ChapterServiceManager(new ChapterDataManager(new ChapterEntityManager(dbContext))); +}); +builder.Services.AddSingleton(provider => +{ + return new LobbyServiceManager(new LobbyDataManager(new LobbyEntityManager(dbContext))); +}); +builder.Services.AddSingleton(provider => +{ + return new PlayerServiceManager(new PlayerDataManager(new PlayerEntityManager(dbContext))); +}); +builder.Services.AddSingleton(provider => +{ + return new QuestionServiceManager(new QuestionDataManager(new QuestionEntityManager(dbContext))); }); var app = builder.Build(); diff --git a/WebApi/WebApi/WebApi.csproj b/WebApi/WebApi/WebApi.csproj index 8887aa1..24f4cbb 100644 --- a/WebApi/WebApi/WebApi.csproj +++ b/WebApi/WebApi/WebApi.csproj @@ -16,8 +16,10 @@ + +