fix: register interfaces for provided services

This commit is contained in:
goat 2023-09-30 01:09:25 +02:00
parent 4b9de31240
commit 4a1b220d4a
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
9 changed files with 46 additions and 20 deletions

View file

@ -19,6 +19,7 @@ namespace Dalamud.Configuration.Internal;
/// Class containing Dalamud settings.
/// </summary>
[Serializable]
[ServiceManager.Service]
internal sealed class DalamudConfiguration : IServiceType, IDisposable
{
private static readonly JsonSerializerSettings SerializerSettings = new()

View file

@ -29,6 +29,7 @@ namespace Dalamud;
/// <summary>
/// The main Dalamud class containing all subsystems.
/// </summary>
[ServiceManager.Service]
internal sealed class Dalamud : IServiceType
{
#region Internals

View file

@ -10,6 +10,7 @@ namespace Dalamud;
/// Struct containing information needed to initialize Dalamud.
/// </summary>
[Serializable]
[ServiceManager.Service]
public record DalamudStartInfo : IServiceType
{
/// <summary>

View file

@ -11,6 +11,7 @@ namespace Dalamud.Game;
/// </summary>
[PluginInterface]
[InterfaceVersion("1.0")]
[ServiceManager.Service]
#pragma warning disable SA1015
[ResolveVia<ISigScanner>]
#pragma warning restore SA1015

View file

@ -16,6 +16,7 @@ namespace Dalamud.IoC.Internal;
/// This is only used to resolve dependencies for plugins.
/// Dalamud services are constructed via Service{T}.ConstructObject at the moment.
/// </summary>
[ServiceManager.Service]
internal class ServiceContainer : IServiceProvider, IServiceType
{
private static readonly ModuleLog Log = new("SERVICECONTAINER");

View file

@ -92,28 +92,24 @@ internal static class ServiceManager
var cacheDir = new DirectoryInfo(Path.Combine(startInfo.WorkingDirectory!, "cachedSigs"));
if (!cacheDir.Exists)
cacheDir.Create();
lock (LoadedServices)
{
Service<Dalamud>.Provide(dalamud);
LoadedServices.Add(typeof(Dalamud));
Service<DalamudStartInfo>.Provide(startInfo);
LoadedServices.Add(typeof(DalamudStartInfo));
void ProvideService<T>(T service) where T : IServiceType
{
Debug.Assert(typeof(T).GetServiceKind().HasFlag(ServiceKind.ManualService), "Provided service must have Service attribute");
Service<T>.Provide(service);
LoadedServices.Add(typeof(T));
}
Service<ReliableFileStorage>.Provide(fs);
LoadedServices.Add(typeof(ReliableFileStorage));
Service<DalamudConfiguration>.Provide(configuration);
LoadedServices.Add(typeof(DalamudConfiguration));
Service<ServiceContainer>.Provide(new ServiceContainer());
LoadedServices.Add(typeof(ServiceContainer));
Service<TargetSigScanner>.Provide(
ProvideService(dalamud);
ProvideService(startInfo);
ProvideService(fs);
ProvideService(configuration);
ProvideService(new ServiceContainer());
ProvideService(
new TargetSigScanner(
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
LoadedServices.Add(typeof(TargetSigScanner));
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
}
using (Timings.Start("CS Resolver Init"))
@ -149,7 +145,8 @@ internal static class ServiceManager
serviceContainer.RegisterInterfaces(serviceType);
// Scoped service do not go through Service<T> and are never early loaded
if (serviceKind.HasFlag(ServiceKind.ScopedService))
// Manual services are provided
if (serviceKind.HasFlag(ServiceKind.ScopedService) || serviceKind.HasFlag(ServiceKind.ManualService))
continue;
Debug.Assert(

View file

@ -23,6 +23,7 @@ namespace Dalamud.Storage;
/// <remarks>
/// This is not an early-loaded service, as it is needed before they are initialized.
/// </remarks>
[ServiceManager.Service]
public class ReliableFileStorage : IServiceType, IDisposable
{
private static readonly ModuleLog Log = new("VFS");