From 5b12560134fdd896f712df157f1cc98de82a12c3 Mon Sep 17 00:00:00 2001 From: HUONG THOMAS <thomas.huong@etu.unistra.fr> Date: Tue, 30 Mar 2021 14:07:58 +0200 Subject: [PATCH] Partie injected in Mainform --- fichier1/fichier1/MainForm.cs | 5 +++-- fichier1/fichier1/Model/Partie.cs | 8 ++++++-- fichier1/fichier1/Program.cs | 14 ++++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/fichier1/fichier1/MainForm.cs b/fichier1/fichier1/MainForm.cs index ce2ff78..dead4fc 100644 --- a/fichier1/fichier1/MainForm.cs +++ b/fichier1/fichier1/MainForm.cs @@ -8,6 +8,7 @@ using System.Windows.Forms; using fichier1.Model; using fichier1.Views; using fichier1.Controllers; +using fichier1.Data; namespace fichier1 { @@ -16,11 +17,11 @@ namespace fichier1 private Partie game; private IGameController ctrl; - public MainForm() + public MainForm(Partie partie) { InitializeComponent(); - this.game = new Partie(); + this.game = partie; this.ctrl = new GameController(this.game); } diff --git a/fichier1/fichier1/Model/Partie.cs b/fichier1/fichier1/Model/Partie.cs index c13c7ed..0919276 100644 --- a/fichier1/fichier1/Model/Partie.cs +++ b/fichier1/fichier1/Model/Partie.cs @@ -15,10 +15,14 @@ namespace fichier1.Model private List<IObserver<Partie>> observers; public int nbMots; - public Partie(int nbMots, float complexite, BddContext context) + public Partie(BddContext context) { - this.nbMots = nbMots; this.context = context; + } + + public void init(int nbMots, float complexite) + { + this.nbMots = nbMots; this.observers = new List<IObserver<Partie>>(); } diff --git a/fichier1/fichier1/Program.cs b/fichier1/fichier1/Program.cs index b374c72..32eff1a 100644 --- a/fichier1/fichier1/Program.cs +++ b/fichier1/fichier1/Program.cs @@ -1,4 +1,5 @@ using fichier1.Data; +using fichier1.Views; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -10,6 +11,7 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using fichier1.Controllers; +using fichier1.Model; namespace fichier1 { @@ -34,14 +36,18 @@ namespace fichier1 Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - //serviceCollection.AddSingleton<Form1>(); + serviceCollection.AddScoped<MainForm>(); + serviceCollection.AddScoped<Partie>(); + serviceCollection.AddScoped<CorrectionMot>(); + serviceCollection.AddScoped<ViewDecoupage>(); + serviceCollection.AddScoped<ViewResultats>(); serviceCollection.AddScoped<IGameController, GameController>(); + ServiceProvider = serviceCollection.BuildServiceProvider(); ServiceProvider.GetRequiredService<BddContext>().Database.EnsureCreated(); - //var form1 = ServiceProvider.GetRequiredService<Form1>(); - - //Application.Run(form1); + var form1 = ServiceProvider.GetRequiredService<MainForm>(); + Application.Run(form1); } } } -- GitLab