From 7ec1de4c76073bc67ff65516c4bc7175addf269c Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Sun, 19 Oct 2025 22:45:50 +0200 Subject: [PATCH] Let IDalamudPluginInterface inherit from IServiceProvider --- Dalamud/IoC/Internal/ServiceScope.cs | 10 ++++++++-- Dalamud/Plugin/DalamudPluginInterface.cs | 6 ++++++ Dalamud/Plugin/IDalamudPluginInterface.cs | 4 +--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Dalamud/IoC/Internal/ServiceScope.cs b/Dalamud/IoC/Internal/ServiceScope.cs index 98209eeb7..8b12dce0b 100644 --- a/Dalamud/IoC/Internal/ServiceScope.cs +++ b/Dalamud/IoC/Internal/ServiceScope.cs @@ -1,4 +1,4 @@ -using System.Collections.Concurrent; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Threading; @@ -12,7 +12,7 @@ namespace Dalamud.IoC.Internal; /// /// Container enabling the creation of scoped services. /// -internal interface IServiceScope : IAsyncDisposable +internal interface IServiceScope : IServiceProvider, IAsyncDisposable { /// /// Register objects that may be injected to scoped services, @@ -57,6 +57,12 @@ internal class ServiceScopeImpl : IServiceScope /// The container this scope will use to create services. public ServiceScopeImpl(ServiceContainer container) => this.container = container; + /// + object? IServiceProvider.GetService(Type serviceType) + { + return ((IServiceProvider)this.container).GetService(serviceType); + } + /// public void RegisterPrivateScopes(params object[] scopes) { diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index 8455ce164..603bed7a5 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -454,6 +454,12 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa #region Dependency Injection + /// + public object? GetService(Type serviceType) + { + return this.plugin.ServiceScope.GetService(serviceType); + } + /// public T? Create(params object[] scopedObjects) where T : class { diff --git a/Dalamud/Plugin/IDalamudPluginInterface.cs b/Dalamud/Plugin/IDalamudPluginInterface.cs index e1dd34f87..d1b6977d4 100644 --- a/Dalamud/Plugin/IDalamudPluginInterface.cs +++ b/Dalamud/Plugin/IDalamudPluginInterface.cs @@ -8,8 +8,6 @@ using System.Threading.Tasks; using Dalamud.Configuration; using Dalamud.Game.Text; using Dalamud.Game.Text.Sanitizer; -using Dalamud.Game.Text.SeStringHandling; -using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface; using Dalamud.Interface.Internal.Windows.PluginInstaller; using Dalamud.Interface.Internal.Windows.Settings; @@ -24,7 +22,7 @@ namespace Dalamud.Plugin; /// /// This interface acts as an interface to various objects needed to interact with Dalamud and the game. /// -public interface IDalamudPluginInterface +public interface IDalamudPluginInterface : IServiceProvider { /// /// Delegate for localization change with two-letter iso lang code.