#region ========================================================================= USING ===================================================================================== using Lumina.Plugins.Contracts.Core.Metadata; using Lumina.Plugins.Contracts.Core.Plugins; using Lumina.Plugins.LocalMusicArtwork.Common.Models.DTO.Settings; using Lumina.Plugins.LocalMusicArtwork.Core; using Lumina.Plugins.LocalMusicArtwork.Core.Settings; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using System; #endregion namespace Lumina.Plugins.LocalMusicArtwork.Common.DependencyInjection; /// /// Utility class for registering the services of the local music artwork providers into the Dependency Injection container. /// internal static class LocalMusicArtworkServices { /// /// Registers the services of the local music artwork providers into the Dependency Injection container. /// /// The service collection to add the services to. /// The unique identifier of the plugin that provides the artwork. /// The updated . internal static IServiceCollection AddLocalMusicArtworkProviders(this IServiceCollection services, Guid pluginId) { ArgumentNullException.ThrowIfNull(services); // Build the runtime settings provider per scope, overlaying the settings persisted by the host over the defaults. services.TryAddScoped(serviceProvider => { LocalMusicArtworkSettingsDto defaults = new(); IPluginSettingsStore? settingsStore = serviceProvider.GetService(); return new LocalMusicArtworkSettingsProvider(settingsStore, pluginId, defaults); }); // Register the artwork providers as keyed by pluginId transient services, so they can be resolved specifically among other IArtworkProvider implementations. services.AddKeyedTransient(pluginId); services.AddKeyedTransient(pluginId); return services; } }