Skip to content

Commit

Permalink
Bugfix history not saved because of different history instance from D…
Browse files Browse the repository at this point in the history
…I container
  • Loading branch information
fahminlb33 committed Feb 26, 2022
1 parent bfb5443 commit 95ae654
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/KFlearning.App/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Windows.Forms;
using KFlearning.App.Resources;
Expand Down Expand Up @@ -112,8 +113,8 @@ private static void RegisterServices()
services.AddTransient<FlutterInstallViewPresenter>();

// register services
services.AddSingleton<HttpClient>();
services.AddSingleton<KFlearningApplicationContext>();
services.AddSingleton<IHistoryService, HistoryService>();

services.AddSingleton<IPathManager, PathManager>();
services.AddSingleton<IProcessManager, ProcessManager>();
Expand All @@ -124,13 +125,18 @@ private static void RegisterServices()
services.AddSingleton<IFlutterGitClient, FlutterGitClient>();
services.AddSingleton<IVisualStudioCodeService, VisualStudioCodeService>();

// -- forwarding pattern using factories
// this is because MS DI will register different instance of the implementation
// https://andrewlock.net/how-to-register-a-service-with-multiple-interfaces-for-in-asp-net-core-di/
services.AddSingleton<HistoryService>();
services.AddSingleton<IHistoryService>(x => x.GetRequiredService<HistoryService>());
services.AddSingleton<IUsesPersistence>(x => x.GetRequiredService<HistoryService>());

services.AddTransient<ITemplateProvider, CppConsoleProvider>();
services.AddTransient<ITemplateProvider, CppFreeglutProvider>();
services.AddTransient<ITemplateProvider, PythonProvider>();
services.AddTransient<ITemplateProvider, WebProvider>();

services.AddTransient<IUsesPersistence, HistoryService>();

// register clients
services.AddTransient<WebClient>();
services.AddTransient<ManualResetEventSlim>();
Expand Down

0 comments on commit 95ae654

Please sign in to comment.