mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
Add IInternal/PublicDisposableService (#1696)
* Add IInternal/PublicDisposableService Plugins are exposed interfaces that are not inherited from `IDisposable`, but services implementing plugin interfaces often implement `IDisposable`. Some plugins may try to call `IDisposable.Dispose` on everything provided, and it also is possible to use `using` clause too eagerly while working on Dalamud itself, such as writing `using var smth = await Service<SomeService>.GetAsync();`. Such behaviors often lead to a difficult-to-debug errors, and making those services either not an `IDisposable` or making `IDisposable.Dispose` do nothing if the object has been loaded would prevent such errors. As `ServiceManager` must be the only class dealing with construction and disposal of services, `IInternalDisposableService` has been added to limit who can dispose the object. `IPublicDisposableService` also has been added to classes that can be constructed and accessed directly by plugins; for those, `Dispose` will be ignored if the instance is a service instance, and only `DisposeService` will respond. In addition, `DalamudPluginInterface` and `UiBuilder` also have been changed so that their `IDisposable.Dispose` no longer respond, and instead, internal functions have been added to only allow disposal from Dalamud. * Cleanup * Postmerge fixes * More explanation on RunOnFrameworkThread(ClearHooks) * Mark ReliableFileStorage public ctor obsolete --------- Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
This commit is contained in:
parent
dcec076ca7
commit
87b9edb448
62 changed files with 441 additions and 381 deletions
|
|
@ -13,7 +13,7 @@ namespace Dalamud.Logging.Internal;
|
|||
/// Class responsible for tracking asynchronous tasks.
|
||||
/// </summary>
|
||||
[ServiceManager.EarlyLoadedService]
|
||||
internal class TaskTracker : IDisposable, IServiceType
|
||||
internal class TaskTracker : IInternalDisposableService
|
||||
{
|
||||
private static readonly ModuleLog Log = new("TT");
|
||||
private static readonly List<TaskInfo> TrackedTasksInternal = new();
|
||||
|
|
@ -119,7 +119,7 @@ internal class TaskTracker : IDisposable, IServiceType
|
|||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Dispose()
|
||||
void IInternalDisposableService.DisposeService()
|
||||
{
|
||||
this.scheduleAndStartHook?.Dispose();
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Dalamud.Logging;
|
|||
#pragma warning disable SA1015
|
||||
[ResolveVia<IPluginLog>]
|
||||
#pragma warning restore SA1015
|
||||
internal class ScopedPluginLogService : IServiceType, IPluginLog, IDisposable
|
||||
internal class ScopedPluginLogService : IServiceType, IPluginLog
|
||||
{
|
||||
private readonly LocalPlugin localPlugin;
|
||||
|
||||
|
|
@ -53,12 +53,6 @@ internal class ScopedPluginLogService : IServiceType, IPluginLog, IDisposable
|
|||
/// </summary>
|
||||
public ILogger Logger { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Fatal(string messageTemplate, params object[] values) =>
|
||||
this.Write(LogEventLevel.Fatal, null, messageTemplate, values);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue