From daa9f72218491e27fd79f693c005482c17433e97 Mon Sep 17 00:00:00 2001
From: goat <16760685+goaaats@users.noreply.github.com>
Date: Sun, 21 May 2023 22:43:28 +0200
Subject: [PATCH] IOC: scoped/on-demand services (#1120)
---
Dalamud.CorePlugin/PluginImpl.cs | 4 +-
.../PluginInstaller/PluginInstallerWindow.cs | 7 +-
Dalamud/IoC/Internal/ServiceContainer.cs | 64 +++++++++--
Dalamud/IoC/Internal/ServiceScope.cs | 101 ++++++++++++++++++
Dalamud/Logging/PluginLog.cs | 69 +++++++++++-
Dalamud/Plugin/DalamudPluginInterface.cs | 74 +++++++------
Dalamud/Plugin/Internal/Types/LocalPlugin.cs | 29 ++++-
Dalamud/ServiceManager.cs | 23 +++-
8 files changed, 309 insertions(+), 62 deletions(-)
create mode 100644 Dalamud/IoC/Internal/ServiceScope.cs
diff --git a/Dalamud.CorePlugin/PluginImpl.cs b/Dalamud.CorePlugin/PluginImpl.cs
index 5ed6d02ac..d352ad2c8 100644
--- a/Dalamud.CorePlugin/PluginImpl.cs
+++ b/Dalamud.CorePlugin/PluginImpl.cs
@@ -54,7 +54,7 @@ namespace Dalamud.CorePlugin
/// Initializes a new instance of the class.
///
/// Dalamud plugin interface.
- public PluginImpl(DalamudPluginInterface pluginInterface)
+ public PluginImpl(DalamudPluginInterface pluginInterface, PluginLog log)
{
try
{
@@ -68,7 +68,7 @@ namespace Dalamud.CorePlugin
Service.Get().AddHandler("/coreplug", new(this.OnCommand) { HelpMessage = $"Access the {this.Name} plugin." });
- PluginLog.Information("CorePlugin ctor!");
+ log.Information("CorePlugin ctor!");
}
catch (Exception ex)
{
diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
index e98810132..c548b33fb 100644
--- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
+++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs
@@ -2252,7 +2252,8 @@ internal class PluginInstallerWindow : Window, IDisposable
disabled = disabled || (plugin.IsOrphaned && !plugin.IsLoaded);
// Disable everything if the plugin failed to load
- disabled = disabled || plugin.State == PluginState.LoadError || plugin.State == PluginState.DependencyResolutionFailed;
+ // Now handled by the first case below
+ // disabled = disabled || plugin.State == PluginState.LoadError || plugin.State == PluginState.DependencyResolutionFailed;
// Disable everything if we're working
disabled = disabled || plugin.State == PluginState.Loading || plugin.State == PluginState.Unloading;
@@ -2263,7 +2264,7 @@ internal class PluginInstallerWindow : Window, IDisposable
StyleModelV1.DalamudStandard.Push();
- if (plugin.State == PluginState.UnloadError && !plugin.IsDev)
+ if (plugin.State is PluginState.UnloadError or PluginState.LoadError or PluginState.DependencyResolutionFailed && !plugin.IsDev)
{
ImGuiComponents.DisabledButton(FontAwesomeIcon.Frown);
@@ -3064,7 +3065,7 @@ internal class PluginInstallerWindow : Window, IDisposable
public static string PluginButtonToolTip_UpdateSingle(string version) => Loc.Localize("InstallerUpdateSingle", "Update to {0}").Format(version);
- public static string PluginButtonToolTip_UnloadFailed => Loc.Localize("InstallerUnloadFailedTooltip", "Plugin unload failed, please restart your game and try again.");
+ public static string PluginButtonToolTip_UnloadFailed => Loc.Localize("InstallerLoadUnloadFailedTooltip", "Plugin load/unload failed, please restart your game and try again.");
#endregion
diff --git a/Dalamud/IoC/Internal/ServiceContainer.cs b/Dalamud/IoC/Internal/ServiceContainer.cs
index 041049643..18d294a3e 100644
--- a/Dalamud/IoC/Internal/ServiceContainer.cs
+++ b/Dalamud/IoC/Internal/ServiceContainer.cs
@@ -6,6 +6,7 @@ using System.Runtime.Serialization;
using System.Threading.Tasks;
using Dalamud.Logging.Internal;
+using Dalamud.Plugin.Internal.Types;
namespace Dalamud.IoC.Internal;
@@ -45,9 +46,12 @@ internal class ServiceContainer : IServiceProvider, IServiceType
///
/// The type of object to create.
/// Scoped objects to be included in the constructor.
+ /// The scope to be used to create scoped services.
/// The created object.
- public async Task