using System; using System.IO; using Jellyfin.Plugin.RecentlyAddedGuard.Core; using Jellyfin.Plugin.RecentlyAddedGuard.Ledger; using Jellyfin.Plugin.RecentlyAddedGuard.Services; using MediaBrowser.Common.Configuration; using MediaBrowser.Controller; using MediaBrowser.Controller.Plugins; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Jellyfin.Plugin.RecentlyAddedGuard; /// /// Registers the plugin services with Jellyfin's DI container. /// public class PluginServiceRegistrator : IPluginServiceRegistrator { /// public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost) { // Runs before the plugin instance exists; factories are evaluated later, when the host starts. serviceCollection.AddSingleton(); serviceCollection.AddSingleton(sp => new LedgerStore( Path.Combine(GetDataFolderPath(sp), LedgerStore.DefaultFileName), sp.GetRequiredService>())); serviceCollection.AddSingleton(sp => new Reconciler( sp.GetRequiredService(), GetOptions, TimeProvider.System, sp.GetRequiredService>())); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(sp => new GuardProcessor( sp.GetRequiredService(), sp.GetRequiredService(), sp.GetRequiredService(), GetOptions, TimeProvider.System, sp.GetRequiredService>())); serviceCollection.AddSingleton(); serviceCollection.AddHostedService(); } private static GuardOptions GetOptions() => Plugin.CurrentConfiguration.ToGuardOptions(); private static string GetDataFolderPath(IServiceProvider serviceProvider) => Plugin.Instance?.DataFolderPath ?? Path.Combine(serviceProvider.GetRequiredService().PluginsPath, typeof(Plugin).Assembly.GetName().Name!); }