mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-13 03:17:43 +01:00
* 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>
25 lines
930 B
C#
25 lines
930 B
C#
namespace Dalamud;
|
|
|
|
/// <summary>
|
|
/// Marker class for service types.
|
|
/// </summary>
|
|
public interface IServiceType
|
|
{
|
|
}
|
|
|
|
/// <summary><see cref="IDisposable"/>, but for <see cref="IServiceType"/>.</summary>
|
|
/// <remarks>Use this to prevent services from accidentally being disposed by plugins or <c>using</c> clauses.</remarks>
|
|
internal interface IInternalDisposableService : IServiceType
|
|
{
|
|
/// <summary>Disposes the service.</summary>
|
|
void DisposeService();
|
|
}
|
|
|
|
/// <summary>An <see cref="IInternalDisposableService"/> which happens to be public and needs to expose
|
|
/// <see cref="IDisposable.Dispose"/>.</summary>
|
|
internal interface IPublicDisposableService : IInternalDisposableService, IDisposable
|
|
{
|
|
/// <summary>Marks that only <see cref="IInternalDisposableService.DisposeService"/> should respond,
|
|
/// while suppressing <see cref="IDisposable.Dispose"/>.</summary>
|
|
void MarkDisposeOnlyFromService();
|
|
}
|