The Free Software Media System - Server Backend & API
Merge remote-tracking branch 'upstream/master' into quickconnect
ConfusedPolarBear5d281adedd0d
diff --cc Emby.Server.Implementations/ApplicationHost.csindex de044a4aa2,be4e05a648..0a349bb331--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@@ -104,11 -100,10 +101,11 @@@ using MediaBrowser.Providers.Subtitlesusing MediaBrowser.WebDashboard.Api;using MediaBrowser.XbmcMetadata.Providers;using Microsoft.AspNetCore.Http;- using Microsoft.AspNetCore.Http.Extensions;- using Microsoft.Extensions.Configuration;using Microsoft.Extensions.DependencyInjection;using Microsoft.Extensions.Logging;+ using Prometheus.DotNetRuntime;using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;++using Emby.Server.Implementations.QuickConnect;namespace Emby.Server.Implementations{@@@ -696,173 -549,117 +551,119 @@@serviceCollection.AddSingleton(ServerConfigurationManager);- LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, LoggerFactory.CreateLogger<LocalizationManager>());- await LocalizationManager.LoadAll().ConfigureAwait(false);- serviceCollection.AddSingleton<ILocalizationManager>(LocalizationManager);-- serviceCollection.AddSingleton<IBlurayExaminer>(new BdInfoExaminer(FileSystemManager));-- UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager);- serviceCollection.AddSingleton(UserDataManager);+ serviceCollection.AddSingleton<ILocalizationManager, LocalizationManager>();- _displayPreferencesRepository = new SqliteDisplayPreferencesRepository(- LoggerFactory.CreateLogger<SqliteDisplayPreferencesRepository>(),- ApplicationPaths,- FileSystemManager);- serviceCollection.AddSingleton<IDisplayPreferencesRepository>(_displayPreferencesRepository);+ serviceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>();- ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, LoggerFactory.CreateLogger<SqliteItemRepository>(), LocalizationManager);- serviceCollection.AddSingleton<IItemRepository>(ItemRepository);+ serviceCollection.AddSingleton<IUserDataRepository, SqliteUserDataRepository>();+ serviceCollection.AddSingleton<IUserDataManager, UserDataManager>();- AuthenticationRepository = GetAuthenticationRepository();- serviceCollection.AddSingleton(AuthenticationRepository);+ serviceCollection.AddSingleton<IDisplayPreferencesRepository, SqliteDisplayPreferencesRepository>();- _userRepository = GetUserRepository();+ serviceCollection.AddSingleton<IItemRepository, SqliteItemRepository>();- UserManager = new UserManager(- LoggerFactory.CreateLogger<UserManager>(),- _userRepository,- XmlSerializer,- NetworkManager,- () => ImageProcessor,- () => DtoService,- this,- JsonSerializer,- FileSystemManager,- cryptoProvider);+ serviceCollection.AddSingleton<IAuthenticationRepository, AuthenticationRepository>();- serviceCollection.AddSingleton(UserManager);+ serviceCollection.AddSingleton<IUserRepository, SqliteUserRepository>();- MediaEncoder = new MediaBrowser.MediaEncoding.Encoder.MediaEncoder(- LoggerFactory.CreateLogger<MediaBrowser.MediaEncoding.Encoder.MediaEncoder>(),- ServerConfigurationManager,- FileSystemManager,- LocalizationManager,- () => SubtitleEncoder,- startupConfig,- StartupOptions.FFmpegPath);- serviceCollection.AddSingleton(MediaEncoder);+ // TODO: Refactor to eliminate the circular dependency here so that Lazy<T> isn't required+ serviceCollection.AddTransient(provider => new Lazy<IDtoService>(provider.GetRequiredService<IDtoService>));+ serviceCollection.AddSingleton<IUserManager, UserManager>();- LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager, MediaEncoder);- serviceCollection.AddSingleton(LibraryManager);+ // TODO: Refactor to eliminate the circular dependency here so that Lazy<T> isn't required+ // TODO: Add StartupOptions.FFmpegPath to IConfiguration and remove this custom activation+ serviceCollection.AddTransient(provider => new Lazy<EncodingHelper>(provider.GetRequiredService<EncodingHelper>));+ serviceCollection.AddSingleton<IMediaEncoder>(provider =>+ ActivatorUtilities.CreateInstance<MediaBrowser.MediaEncoding.Encoder.MediaEncoder>(provider, _startupOptions.FFmpegPath ?? string.Empty));- var musicManager = new MusicManager(LibraryManager);- serviceCollection.AddSingleton<IMusicManager>(musicManager);+ // TODO: Refactor to eliminate the circular dependencies here so that Lazy<T> isn't required+ serviceCollection.AddTransient(provider => new Lazy<ILibraryMonitor>(provider.GetRequiredService<ILibraryMonitor>));+ serviceCollection.AddTransient(provider => new Lazy<IProviderManager>(provider.GetRequiredService<IProviderManager>));+ serviceCollection.AddTransient(provider => new Lazy<IUserViewManager>(provider.GetRequiredService<IUserViewManager>));+ serviceCollection.AddSingleton<ILibraryManager, LibraryManager>();- LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager);- serviceCollection.AddSingleton(LibraryMonitor);+ serviceCollection.AddSingleton<IMusicManager, MusicManager>();- serviceCollection.AddSingleton<ISearchEngine>(new SearchEngine(LoggerFactory, LibraryManager, UserManager));+ serviceCollection.AddSingleton<ILibraryMonitor, LibraryMonitor>();- CertificateInfo = GetCertificateInfo(true);- Certificate = GetCertificate(CertificateInfo);+ serviceCollection.AddSingleton<ISearchEngine, SearchEngine>();serviceCollection.AddSingleton<ServiceController>();- serviceCollection.AddSingleton<IHttpListener, WebSocketSharpListener>();serviceCollection.AddSingleton<IHttpServer, HttpListenerHost>();- ImageProcessor = new ImageProcessor(LoggerFactory.CreateLogger<ImageProcessor>(), ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder);- serviceCollection.AddSingleton(ImageProcessor);+ serviceCollection.AddSingleton<IImageProcessor, ImageProcessor>();- TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager, ServerConfigurationManager);- serviceCollection.AddSingleton(TVSeriesManager);+ serviceCollection.AddSingleton<ITVSeriesManager, TVSeriesManager>();- DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager);- serviceCollection.AddSingleton(DeviceManager);+ serviceCollection.AddSingleton<IDeviceManager, DeviceManager>();- MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder);- serviceCollection.AddSingleton(MediaSourceManager);+ serviceCollection.AddSingleton<IMediaSourceManager, MediaSourceManager>();- SubtitleManager = new SubtitleManager(LoggerFactory, FileSystemManager, LibraryMonitor, MediaSourceManager, LocalizationManager);- serviceCollection.AddSingleton(SubtitleManager);+ serviceCollection.AddSingleton<ISubtitleManager, SubtitleManager>();- ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LoggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer);- serviceCollection.AddSingleton(ProviderManager);+ serviceCollection.AddSingleton<IProviderManager, ProviderManager>();- DtoService = new DtoService(LoggerFactory, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ProviderManager, this, () => MediaSourceManager, () => LiveTvManager);- serviceCollection.AddSingleton(DtoService);+ // TODO: Refactor to eliminate the circular dependency here so that Lazy<T> isn't required+ serviceCollection.AddTransient(provider => new Lazy<ILiveTvManager>(provider.GetRequiredService<ILiveTvManager>));+ serviceCollection.AddSingleton<IDtoService, DtoService>();- ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LoggerFactory, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, ProviderManager);- serviceCollection.AddSingleton(ChannelManager);+ serviceCollection.AddSingleton<IChannelManager, ChannelManager>();- SessionManager = new SessionManager(- LoggerFactory.CreateLogger<SessionManager>(),- UserDataManager,- LibraryManager,- UserManager,- musicManager,- DtoService,- ImageProcessor,- this,- AuthenticationRepository,- DeviceManager,- MediaSourceManager);- serviceCollection.AddSingleton(SessionManager);+ serviceCollection.AddSingleton<ISessionManager, SessionManager>();- serviceCollection.AddSingleton<IDlnaManager>(- new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LoggerFactory, JsonSerializer, this));+ serviceCollection.AddSingleton<IDlnaManager, DlnaManager>();- CollectionManager = new CollectionManager(LibraryManager, ApplicationPaths, LocalizationManager, FileSystemManager, LibraryMonitor, LoggerFactory, ProviderManager);- serviceCollection.AddSingleton(CollectionManager);+ serviceCollection.AddSingleton<ICollectionManager, CollectionManager>();- serviceCollection.AddSingleton(typeof(IPlaylistManager), typeof(PlaylistManager));+ serviceCollection.AddSingleton<IPlaylistManager, PlaylistManager>();- LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, LoggerFactory, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, FileSystemManager, () => ChannelManager);- serviceCollection.AddSingleton(LiveTvManager);+ serviceCollection.AddSingleton<ISyncPlayManager, SyncPlayManager>();- UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, UserManager, ChannelManager, LiveTvManager, ServerConfigurationManager);- serviceCollection.AddSingleton(UserViewManager);+ serviceCollection.AddSingleton<LiveTvDtoService>();+ serviceCollection.AddSingleton<ILiveTvManager, LiveTvManager>();- NotificationManager = new NotificationManager(- LoggerFactory.CreateLogger<NotificationManager>(),- UserManager,- ServerConfigurationManager);- serviceCollection.AddSingleton(NotificationManager);+ serviceCollection.AddSingleton<IUserViewManager, UserViewManager>();- serviceCollection.AddSingleton<IDeviceDiscovery>(new DeviceDiscovery(ServerConfigurationManager));+ serviceCollection.AddSingleton<INotificationManager, NotificationManager>();- ChapterManager = new ChapterManager(ItemRepository);- serviceCollection.AddSingleton(ChapterManager);+ serviceCollection.AddSingleton<IDeviceDiscovery, DeviceDiscovery>();- EncodingManager = new MediaEncoder.EncodingManager(- LoggerFactory.CreateLogger<MediaEncoder.EncodingManager>(),- FileSystemManager,- MediaEncoder,- ChapterManager,- LibraryManager);- serviceCollection.AddSingleton(EncodingManager);+ serviceCollection.AddSingleton<IChapterManager, ChapterManager>();- var activityLogRepo = GetActivityLogRepository();- serviceCollection.AddSingleton(activityLogRepo);- serviceCollection.AddSingleton<IActivityManager>(new ActivityManager(LoggerFactory, activityLogRepo, UserManager));+ serviceCollection.AddSingleton<IEncodingManager, MediaEncoder.EncodingManager>();- var authContext = new AuthorizationContext(AuthenticationRepository, UserManager);- serviceCollection.AddSingleton<IAuthorizationContext>(authContext);- serviceCollection.AddSingleton<ISessionContext>(new SessionContext(UserManager, authContext, SessionManager));+ serviceCollection.AddSingleton<IAuthorizationContext, AuthorizationContext>();+ serviceCollection.AddSingleton<ISessionContext, SessionContext>();- AuthService = new AuthService(LoggerFactory.CreateLogger<AuthService>(), authContext, ServerConfigurationManager, SessionManager, NetworkManager);- serviceCollection.AddSingleton(AuthService);+ serviceCollection.AddSingleton<IAuthService, AuthService>();++ serviceCollection.AddSingleton<IQuickConnect, QuickConnectManager>();- SubtitleEncoder = new MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder(- LibraryManager,- LoggerFactory.CreateLogger<MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder>(),- ApplicationPaths,- FileSystemManager,- MediaEncoder,- HttpClient,- MediaSourceManager);- serviceCollection.AddSingleton(SubtitleEncoder);+ serviceCollection.AddSingleton<ISubtitleEncoder, MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder>();- serviceCollection.AddSingleton(typeof(IResourceFileManager), typeof(ResourceFileManager));+ serviceCollection.AddSingleton<IResourceFileManager, ResourceFileManager>();serviceCollection.AddSingleton<EncodingHelper>();- serviceCollection.AddSingleton(typeof(IAttachmentExtractor), typeof(MediaBrowser.MediaEncoding.Attachments.AttachmentExtractor));+ serviceCollection.AddSingleton<IAttachmentExtractor, MediaBrowser.MediaEncoding.Attachments.AttachmentExtractor>();+ }- serviceCollection.AddSingleton(typeof(IQuickConnect), typeof(QuickConnect.QuickConnectManager));+- _displayPreferencesRepository.Initialize();+ /// <summary>+ /// Create services registered with the service container that need to be initialized at application startup.+ /// </summary>+ /// <returns>A task representing the service initialization operation.</returns>+ public async Task InitializeServices()+ {+ var localizationManager = (LocalizationManager)Resolve<ILocalizationManager>();+ await localizationManager.LoadAll().ConfigureAwait(false);++ _mediaEncoder = Resolve<IMediaEncoder>();+ _sessionManager = Resolve<ISessionManager>();+ _httpServer = Resolve<IHttpServer>();+ _httpClient = Resolve<IHttpClient>();- var userDataRepo = new SqliteUserDataRepository(LoggerFactory.CreateLogger<SqliteUserDataRepository>(), ApplicationPaths);+ ((SqliteDisplayPreferencesRepository)Resolve<IDisplayPreferencesRepository>()).Initialize();+ ((AuthenticationRepository)Resolve<IAuthenticationRepository>()).Initialize();+ ((SqliteUserRepository)Resolve<IUserRepository>()).Initialize();SetStaticProperties();