#region ========================================================================= USING =====================================================================================
using Nemera.Plugins.Contracts.Core.Metadata;
using Nemera.Plugins.Contracts.Core.Plugins;
using Nemera.Plugins.LocalMusicArtwork.Common.Models.DTO.Settings;
using Nemera.Plugins.LocalMusicArtwork.Core;
using Nemera.Plugins.LocalMusicArtwork.Core.Settings;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
#endregion
namespace Nemera.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;
}
}