using System; using Emby.Server.Implementations.QuickConnect; using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.QuickConnect; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using StackExchange.Redis; namespace Jellyfin.Server.Extensions; /// /// Extensions for registering the quick connect store. /// public static class QuickConnectStoreServiceCollectionExtensions { /// /// Registers the quick connect store, Redis-backed when a connection string is configured and /// process-local otherwise, and reports the selected store at . /// /// /// The connection string is only set for a multi-instance deployment, which is the only shape where /// the initiate, authorize and exchange legs of one flow can land on different instances. Set but /// unreachable is a misconfigured deployment rather than a single-instance one, so it fails rather /// than quietly handing out a store the other instances cannot see. /// /// The service collection. /// The configuration to read the Redis connection string from. /// The logger to report the selected store on. /// The updated service collection. public static IServiceCollection AddQuickConnectStore( this IServiceCollection serviceCollection, IConfiguration configuration, ILogger logger) { ArgumentNullException.ThrowIfNull(configuration); ArgumentNullException.ThrowIfNull(logger); if (string.IsNullOrEmpty(configuration[TranscodeStoreOptions.RedisConnectionStringKey])) { logger.LogInformation( "Quick connect store: {Store}. A quick connect flow has to complete against one instance; set {Key} to share it.", nameof(InMemoryQuickConnectStore), TranscodeStoreOptions.RedisConnectionStringKey); return serviceCollection.AddSingleton(); } logger.LogInformation( "Quick connect store: {Store}. Quick connect flows complete across any instance.", nameof(RedisQuickConnectStore)); return serviceCollection.AddSingleton(sp => new RedisQuickConnectStore( sp.GetRequiredService(), sp.GetRequiredService>())); } }