diff options
Diffstat (limited to 'Emby.Server.Implementations/ApplicationHost.cs')
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 178 |
1 files changed, 99 insertions, 79 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 0201ed7a3..4f47d1999 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -37,10 +37,10 @@ using Emby.Server.Implementations.LiveTv; using Emby.Server.Implementations.Localization; using Emby.Server.Implementations.Net; using Emby.Server.Implementations.Playlists; +using Emby.Server.Implementations.QuickConnect; using Emby.Server.Implementations.ScheduledTasks; using Emby.Server.Implementations.Security; using Emby.Server.Implementations.Serialization; -using Emby.Server.Implementations.Services; using Emby.Server.Implementations.Session; using Emby.Server.Implementations.SyncPlay; using Emby.Server.Implementations.TV; @@ -53,7 +53,6 @@ using MediaBrowser.Common.Net; using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Updates; using MediaBrowser.Controller; -using MediaBrowser.Controller.Authentication; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Chapters; using MediaBrowser.Controller.Collections; @@ -72,6 +71,7 @@ using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Playlists; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Providers; +using MediaBrowser.Controller.QuickConnect; using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Security; using MediaBrowser.Controller.Session; @@ -89,7 +89,6 @@ using MediaBrowser.Model.IO; using MediaBrowser.Model.MediaInfo; using MediaBrowser.Model.Net; using MediaBrowser.Model.Serialization; -using MediaBrowser.Model.Services; using MediaBrowser.Model.System; using MediaBrowser.Model.Tasks; using MediaBrowser.Providers.Chapters; @@ -98,6 +97,7 @@ using MediaBrowser.Providers.Plugins.TheTvdb; using MediaBrowser.Providers.Subtitles; using MediaBrowser.XbmcMetadata.Providers; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Prometheus.DotNetRuntime; @@ -173,6 +173,8 @@ namespace Emby.Server.Implementations /// </summary> protected ILogger<ApplicationHost> Logger { get; } + protected IServiceCollection ServiceCollection { get; } + private IPlugin[] _plugins; /// <summary> @@ -238,9 +240,11 @@ namespace Emby.Server.Implementations ILoggerFactory loggerFactory, IStartupOptions options, IFileSystem fileSystem, - INetworkManager networkManager) + INetworkManager networkManager, + IServiceCollection serviceCollection) { _xmlSerializer = new MyXmlSerializer(); + ServiceCollection = serviceCollection; _networkManager = networkManager; networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets; @@ -464,7 +468,7 @@ namespace Emby.Server.Implementations } /// <inheritdoc/> - public void Init(IServiceCollection serviceCollection) + public void Init() { HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber; @@ -493,7 +497,7 @@ namespace Emby.Server.Implementations DiscoverTypes(); - RegisterServices(serviceCollection); + RegisterServices(); } public Task ExecuteHttpHandlerAsync(HttpContext context, Func<Task> next) @@ -502,136 +506,137 @@ namespace Emby.Server.Implementations /// <summary> /// Registers services/resources with the service collection that will be available via DI. /// </summary> - protected virtual void RegisterServices(IServiceCollection serviceCollection) + protected virtual void RegisterServices() { - serviceCollection.AddSingleton(_startupOptions); - - serviceCollection.AddMemoryCache(); + ServiceCollection.AddSingleton(_startupOptions); - serviceCollection.AddSingleton(ConfigurationManager); - serviceCollection.AddSingleton<IApplicationHost>(this); + ServiceCollection.AddMemoryCache(); - serviceCollection.AddSingleton<IApplicationPaths>(ApplicationPaths); + ServiceCollection.AddSingleton(ConfigurationManager); + ServiceCollection.AddSingleton<IApplicationHost>(this); - serviceCollection.AddSingleton<IJsonSerializer, JsonSerializer>(); + ServiceCollection.AddSingleton<IApplicationPaths>(ApplicationPaths); - serviceCollection.AddSingleton(_fileSystemManager); - serviceCollection.AddSingleton<TvdbClientManager>(); + ServiceCollection.AddSingleton<IJsonSerializer, JsonSerializer>(); - serviceCollection.AddSingleton<IHttpClient, HttpClientManager.HttpClientManager>(); + ServiceCollection.AddSingleton(_fileSystemManager); + ServiceCollection.AddSingleton<TvdbClientManager>(); - serviceCollection.AddSingleton(_networkManager); + ServiceCollection.AddSingleton<IHttpClient, HttpClientManager.HttpClientManager>(); - serviceCollection.AddSingleton<IIsoManager, IsoManager>(); + ServiceCollection.AddSingleton(_networkManager); - serviceCollection.AddSingleton<ITaskManager, TaskManager>(); + ServiceCollection.AddSingleton<IIsoManager, IsoManager>(); - serviceCollection.AddSingleton(_xmlSerializer); + ServiceCollection.AddSingleton<ITaskManager, TaskManager>(); - serviceCollection.AddSingleton<IStreamHelper, StreamHelper>(); + ServiceCollection.AddSingleton(_xmlSerializer); - serviceCollection.AddSingleton<ICryptoProvider, CryptographyProvider>(); + ServiceCollection.AddSingleton<IStreamHelper, StreamHelper>(); - serviceCollection.AddSingleton<ISocketFactory, SocketFactory>(); + ServiceCollection.AddSingleton<ICryptoProvider, CryptographyProvider>(); - serviceCollection.AddSingleton<IInstallationManager, InstallationManager>(); + ServiceCollection.AddSingleton<ISocketFactory, SocketFactory>(); - serviceCollection.AddSingleton<IZipClient, ZipClient>(); + ServiceCollection.AddSingleton<IInstallationManager, InstallationManager>(); - serviceCollection.AddSingleton<IHttpResultFactory, HttpResultFactory>(); + ServiceCollection.AddSingleton<IZipClient, ZipClient>(); - serviceCollection.AddSingleton<IServerApplicationHost>(this); - serviceCollection.AddSingleton<IServerApplicationPaths>(ApplicationPaths); + ServiceCollection.AddSingleton<IServerApplicationHost>(this); + ServiceCollection.AddSingleton<IServerApplicationPaths>(ApplicationPaths); - serviceCollection.AddSingleton(ServerConfigurationManager); + ServiceCollection.AddSingleton(ServerConfigurationManager); - serviceCollection.AddSingleton<ILocalizationManager, LocalizationManager>(); + ServiceCollection.AddSingleton<ILocalizationManager, LocalizationManager>(); - serviceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>(); + ServiceCollection.AddSingleton<IBlurayExaminer, BdInfoExaminer>(); - serviceCollection.AddSingleton<IUserDataRepository, SqliteUserDataRepository>(); - serviceCollection.AddSingleton<IUserDataManager, UserDataManager>(); + ServiceCollection.AddSingleton<IUserDataRepository, SqliteUserDataRepository>(); + ServiceCollection.AddSingleton<IUserDataManager, UserDataManager>(); - serviceCollection.AddSingleton<IItemRepository, SqliteItemRepository>(); + ServiceCollection.AddSingleton<IItemRepository, SqliteItemRepository>(); - serviceCollection.AddSingleton<IAuthenticationRepository, AuthenticationRepository>(); + ServiceCollection.AddSingleton<IAuthenticationRepository, AuthenticationRepository>(); // 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.AddTransient(provider => new Lazy<IDtoService>(provider.GetRequiredService<IDtoService>)); // TODO: Refactor to eliminate the circular dependency here so that Lazy<T> isn't required - serviceCollection.AddTransient(provider => new Lazy<EncodingHelper>(provider.GetRequiredService<EncodingHelper>)); - serviceCollection.AddSingleton<IMediaEncoder, MediaBrowser.MediaEncoding.Encoder.MediaEncoder>(); + ServiceCollection.AddTransient(provider => new Lazy<EncodingHelper>(provider.GetRequiredService<EncodingHelper>)); + ServiceCollection.AddSingleton<IMediaEncoder, MediaBrowser.MediaEncoding.Encoder.MediaEncoder>(); // 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>(); + 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>(); - serviceCollection.AddSingleton<IMusicManager, MusicManager>(); + ServiceCollection.AddSingleton<IMusicManager, MusicManager>(); - serviceCollection.AddSingleton<ILibraryMonitor, LibraryMonitor>(); + ServiceCollection.AddSingleton<ILibraryMonitor, LibraryMonitor>(); - serviceCollection.AddSingleton<ISearchEngine, SearchEngine>(); + ServiceCollection.AddSingleton<ISearchEngine, SearchEngine>(); - serviceCollection.AddSingleton<ServiceController>(); - serviceCollection.AddSingleton<IHttpServer, HttpListenerHost>(); + ServiceCollection.AddSingleton<IHttpServer, HttpListenerHost>(); - serviceCollection.AddSingleton<IImageProcessor, ImageProcessor>(); + ServiceCollection.AddSingleton<IImageProcessor, ImageProcessor>(); - serviceCollection.AddSingleton<ITVSeriesManager, TVSeriesManager>(); + ServiceCollection.AddSingleton<ITVSeriesManager, TVSeriesManager>(); - serviceCollection.AddSingleton<IDeviceManager, DeviceManager>(); + ServiceCollection.AddSingleton<IDeviceManager, DeviceManager>(); - serviceCollection.AddSingleton<IMediaSourceManager, MediaSourceManager>(); + ServiceCollection.AddSingleton<IMediaSourceManager, MediaSourceManager>(); - serviceCollection.AddSingleton<ISubtitleManager, SubtitleManager>(); + ServiceCollection.AddSingleton<ISubtitleManager, SubtitleManager>(); - serviceCollection.AddSingleton<IProviderManager, ProviderManager>(); + ServiceCollection.AddSingleton<IProviderManager, ProviderManager>(); // 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>(); + ServiceCollection.AddTransient(provider => new Lazy<ILiveTvManager>(provider.GetRequiredService<ILiveTvManager>)); + ServiceCollection.AddSingleton<IDtoService, DtoService>(); - serviceCollection.AddSingleton<IChannelManager, ChannelManager>(); + ServiceCollection.AddSingleton<IChannelManager, ChannelManager>(); - serviceCollection.AddSingleton<ISessionManager, SessionManager>(); + ServiceCollection.AddSingleton<ISessionManager, SessionManager>(); - serviceCollection.AddSingleton<IDlnaManager, DlnaManager>(); + ServiceCollection.AddSingleton<IDlnaManager, DlnaManager>(); - serviceCollection.AddSingleton<ICollectionManager, CollectionManager>(); + ServiceCollection.AddSingleton<ICollectionManager, CollectionManager>(); - serviceCollection.AddSingleton<IPlaylistManager, PlaylistManager>(); + ServiceCollection.AddSingleton<IPlaylistManager, PlaylistManager>(); - serviceCollection.AddSingleton<ISyncPlayManager, SyncPlayManager>(); + ServiceCollection.AddSingleton<ISyncPlayManager, SyncPlayManager>(); - serviceCollection.AddSingleton<LiveTvDtoService>(); - serviceCollection.AddSingleton<ILiveTvManager, LiveTvManager>(); + ServiceCollection.AddSingleton<LiveTvDtoService>(); + ServiceCollection.AddSingleton<ILiveTvManager, LiveTvManager>(); - serviceCollection.AddSingleton<IUserViewManager, UserViewManager>(); + ServiceCollection.AddSingleton<IUserViewManager, UserViewManager>(); - serviceCollection.AddSingleton<INotificationManager, NotificationManager>(); + ServiceCollection.AddSingleton<INotificationManager, NotificationManager>(); - serviceCollection.AddSingleton<IDeviceDiscovery, DeviceDiscovery>(); + ServiceCollection.AddSingleton<IDeviceDiscovery, DeviceDiscovery>(); - serviceCollection.AddSingleton<IChapterManager, ChapterManager>(); + ServiceCollection.AddSingleton<IChapterManager, ChapterManager>(); - serviceCollection.AddSingleton<IEncodingManager, MediaEncoder.EncodingManager>(); + ServiceCollection.AddSingleton<IEncodingManager, MediaEncoder.EncodingManager>(); - serviceCollection.AddSingleton<IAuthorizationContext, AuthorizationContext>(); - serviceCollection.AddSingleton<ISessionContext, SessionContext>(); + ServiceCollection.AddSingleton<IAuthorizationContext, AuthorizationContext>(); + ServiceCollection.AddSingleton<ISessionContext, SessionContext>(); - serviceCollection.AddSingleton<IAuthService, AuthService>(); + ServiceCollection.AddSingleton<IAuthService, AuthService>(); + ServiceCollection.AddSingleton<IQuickConnect, QuickConnectManager>(); - serviceCollection.AddSingleton<ISubtitleEncoder, MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder>(); + ServiceCollection.AddSingleton<ISubtitleEncoder, MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder>(); - serviceCollection.AddSingleton<IResourceFileManager, ResourceFileManager>(); - serviceCollection.AddSingleton<EncodingHelper>(); + ServiceCollection.AddSingleton<IResourceFileManager, ResourceFileManager>(); + ServiceCollection.AddSingleton<EncodingHelper>(); - serviceCollection.AddSingleton<IAttachmentExtractor, MediaBrowser.MediaEncoding.Attachments.AttachmentExtractor>(); + ServiceCollection.AddSingleton<IAttachmentExtractor, MediaBrowser.MediaEncoding.Attachments.AttachmentExtractor>(); - serviceCollection.AddSingleton<TranscodingJobHelper>(); + ServiceCollection.AddSingleton<TranscodingJobHelper>(); + ServiceCollection.AddScoped<MediaInfoHelper>(); + ServiceCollection.AddScoped<AudioHelper>(); + ServiceCollection.AddScoped<DynamicHlsHelper>(); } /// <summary> @@ -747,7 +752,6 @@ namespace Emby.Server.Implementations CollectionFolder.XmlSerializer = _xmlSerializer; CollectionFolder.JsonSerializer = Resolve<IJsonSerializer>(); CollectionFolder.ApplicationHost = this; - AuthenticatedAttribute.AuthService = Resolve<IAuthService>(); } /// <summary> @@ -767,7 +771,7 @@ namespace Emby.Server.Implementations .Where(i => i != null) .ToArray(); - _httpServer.Init(GetExportTypes<IService>(), GetExports<IWebSocketListener>(), GetUrlPrefixes()); + _httpServer.Init(GetExports<IWebSocketListener>(), GetUrlPrefixes()); Resolve<ILibraryManager>().AddParts( GetExports<IResolverIgnoreRule>(), @@ -831,6 +835,8 @@ namespace Emby.Server.Implementations { hasPluginConfiguration.SetStartupInfo(s => Directory.CreateDirectory(s)); } + + plugin.RegisterServices(ServiceCollection); } catch (Exception ex) { @@ -1385,6 +1391,20 @@ namespace Emby.Server.Implementations _plugins = list.ToArray(); } + public IEnumerable<Assembly> GetApiPluginAssemblies() + { + var assemblies = _allConcreteTypes + .Where(i => typeof(ControllerBase).IsAssignableFrom(i)) + .Select(i => i.Assembly) + .Distinct(); + + foreach (var assembly in assemblies) + { + Logger.LogDebug("Found API endpoints in plugin {name}", assembly.FullName); + yield return assembly; + } + } + public virtual void LaunchUrl(string url) { if (!CanLaunchWebBrowser) |
