Files
Jellyfin-Comments/Jellyfin.Plugin.RedditComments/PluginServiceRegistrator.cs
Gabrieal Jimmy 378677acda fix 2
2026-07-16 14:07:16 -05:00

41 lines
1.6 KiB
C#

using System.IO;
using Jellyfin.Plugin.RedditComments.Services;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.RedditComments;
/// <summary>
/// Registers the plugin's services in the Jellyfin DI container.
/// </summary>
public class PluginServiceRegistrator : IPluginServiceRegistrator
{
/// <inheritdoc />
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
{
serviceCollection.AddSingleton<RateLimiter>();
serviceCollection.AddSingleton(sp => new RedditClient(sp.GetRequiredService<ILogger<RedditClient>>(), sp.GetRequiredService<RateLimiter>()));
// The path is resolved inside the factory (not eagerly here) because the host's service
// provider does not exist yet while RegisterServices is running.
serviceCollection.AddSingleton(sp =>
{
var dbPath = Path.Combine(
sp.GetRequiredService<IApplicationPaths>().PluginConfigurationsPath,
"RedditComments",
"reddit-comments.db");
return new CommentCache(dbPath, sp.GetRequiredService<ILogger<CommentCache>>());
});
serviceCollection.AddSingleton(sp => new RedditCommentsService(
sp.GetRequiredService<ILogger<RedditCommentsService>>(),
sp.GetRequiredService<RedditClient>(),
sp.GetRequiredService<CommentCache>()));
serviceCollection.AddHostedService<WebScriptInjector>();
}
}