Let IDalamudPluginInterface inherit from IServiceProvider

This commit is contained in:
Haselnussbomber 2025-10-19 22:45:50 +02:00
parent 05f31265eb
commit 7ec1de4c76
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
3 changed files with 15 additions and 5 deletions

View file

@ -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;
/// <summary>
/// Container enabling the creation of scoped services.
/// </summary>
internal interface IServiceScope : IAsyncDisposable
internal interface IServiceScope : IServiceProvider, IAsyncDisposable
{
/// <summary>
/// Register objects that may be injected to scoped services,
@ -57,6 +57,12 @@ internal class ServiceScopeImpl : IServiceScope
/// <param name="container">The container this scope will use to create services.</param>
public ServiceScopeImpl(ServiceContainer container) => this.container = container;
/// <inheritdoc/>
object? IServiceProvider.GetService(Type serviceType)
{
return ((IServiceProvider)this.container).GetService(serviceType);
}
/// <inheritdoc/>
public void RegisterPrivateScopes(params object[] scopes)
{

View file

@ -454,6 +454,12 @@ internal sealed class DalamudPluginInterface : IDalamudPluginInterface, IDisposa
#region Dependency Injection
/// <inheritdoc/>
public object? GetService(Type serviceType)
{
return this.plugin.ServiceScope.GetService(serviceType);
}
/// <inheritdoc/>
public T? Create<T>(params object[] scopedObjects) where T : class
{

View file

@ -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;
/// <summary>
/// This interface acts as an interface to various objects needed to interact with Dalamud and the game.
/// </summary>
public interface IDalamudPluginInterface
public interface IDalamudPluginInterface : IServiceProvider
{
/// <summary>
/// Delegate for localization change with two-letter iso lang code.