CoreAppHost.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Emby.Server.Implementations;
  5. using Emby.Server.Implementations.Session;
  6. using Jellyfin.Api.WebSocketListeners;
  7. using Jellyfin.Database.Implementations;
  8. using Jellyfin.Drawing;
  9. using Jellyfin.Drawing.Skia;
  10. using Jellyfin.LiveTv;
  11. using Jellyfin.Server.Implementations.Activity;
  12. using Jellyfin.Server.Implementations.Devices;
  13. using Jellyfin.Server.Implementations.Events;
  14. using Jellyfin.Server.Implementations.Extensions;
  15. using Jellyfin.Server.Implementations.Security;
  16. using Jellyfin.Server.Implementations.Trickplay;
  17. using Jellyfin.Server.Implementations.Users;
  18. using MediaBrowser.Controller;
  19. using MediaBrowser.Controller.Authentication;
  20. using MediaBrowser.Controller.BaseItemManager;
  21. using MediaBrowser.Controller.Devices;
  22. using MediaBrowser.Controller.Drawing;
  23. using MediaBrowser.Controller.Events;
  24. using MediaBrowser.Controller.Library;
  25. using MediaBrowser.Controller.Lyrics;
  26. using MediaBrowser.Controller.Net;
  27. using MediaBrowser.Controller.Security;
  28. using MediaBrowser.Controller.Trickplay;
  29. using MediaBrowser.Model.Activity;
  30. using MediaBrowser.Providers.Lyric;
  31. using Microsoft.Extensions.Configuration;
  32. using Microsoft.Extensions.DependencyInjection;
  33. using Microsoft.Extensions.Logging;
  34. namespace Jellyfin.Server
  35. {
  36. /// <summary>
  37. /// Implementation of the abstract <see cref="ApplicationHost" /> class.
  38. /// </summary>
  39. public class CoreAppHost : ApplicationHost
  40. {
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="CoreAppHost" /> class.
  43. /// </summary>
  44. /// <param name="applicationPaths">The <see cref="ServerApplicationPaths" /> to be used by the <see cref="CoreAppHost" />.</param>
  45. /// <param name="loggerFactory">The <see cref="ILoggerFactory" /> to be used by the <see cref="CoreAppHost" />.</param>
  46. /// <param name="options">The <see cref="StartupOptions" /> to be used by the <see cref="CoreAppHost" />.</param>
  47. /// <param name="startupConfig">The <see cref="IConfiguration" /> to be used by the <see cref="CoreAppHost" />.</param>
  48. public CoreAppHost(
  49. IServerApplicationPaths applicationPaths,
  50. ILoggerFactory loggerFactory,
  51. IStartupOptions options,
  52. IConfiguration startupConfig)
  53. : base(
  54. applicationPaths,
  55. loggerFactory,
  56. options,
  57. startupConfig)
  58. {
  59. }
  60. /// <inheritdoc/>
  61. protected override void RegisterServices(IServiceCollection serviceCollection)
  62. {
  63. // Register an image encoder
  64. bool useSkiaEncoder = SkiaEncoder.IsNativeLibAvailable();
  65. Type imageEncoderType = useSkiaEncoder
  66. ? typeof(SkiaEncoder)
  67. : typeof(NullImageEncoder);
  68. serviceCollection.AddSingleton(typeof(IImageEncoder), imageEncoderType);
  69. // Log a warning if the Skia encoder could not be used
  70. if (!useSkiaEncoder)
  71. {
  72. Logger.LogWarning("Skia not available. Will fallback to {ImageEncoder}.", nameof(NullImageEncoder));
  73. }
  74. serviceCollection.AddEventServices();
  75. serviceCollection.AddSingleton<IBaseItemManager, BaseItemManager>();
  76. serviceCollection.AddSingleton<IEventManager, EventManager>();
  77. serviceCollection.AddSingleton<IActivityManager, ActivityManager>();
  78. serviceCollection.AddSingleton<IUserManager, UserManager>();
  79. serviceCollection.AddSingleton<IAuthenticationProvider, DefaultAuthenticationProvider>();
  80. serviceCollection.AddSingleton<IAuthenticationProvider, InvalidAuthProvider>();
  81. serviceCollection.AddSingleton<IPasswordResetProvider, DefaultPasswordResetProvider>();
  82. serviceCollection.AddScoped<IDisplayPreferencesManager, DisplayPreferencesManager>();
  83. serviceCollection.AddSingleton<IDeviceManager, DeviceManager>();
  84. serviceCollection.AddSingleton<ITrickplayManager, TrickplayManager>();
  85. // TODO search the assemblies instead of adding them manually?
  86. serviceCollection.AddSingleton<IWebSocketListener, SessionWebSocketListener>();
  87. serviceCollection.AddSingleton<IWebSocketListener, ActivityLogWebSocketListener>();
  88. serviceCollection.AddSingleton<IWebSocketListener, ScheduledTasksWebSocketListener>();
  89. serviceCollection.AddSingleton<IWebSocketListener, SessionInfoWebSocketListener>();
  90. serviceCollection.AddSingleton<IAuthorizationContext, AuthorizationContext>();
  91. serviceCollection.AddScoped<IAuthenticationManager, AuthenticationManager>();
  92. foreach (var type in GetExportTypes<ILyricProvider>())
  93. {
  94. serviceCollection.AddSingleton(typeof(ILyricProvider), type);
  95. }
  96. foreach (var type in GetExportTypes<ILyricParser>())
  97. {
  98. serviceCollection.AddSingleton(typeof(ILyricParser), type);
  99. }
  100. base.RegisterServices(serviceCollection);
  101. }
  102. /// <inheritdoc />
  103. protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
  104. {
  105. // Jellyfin.Server
  106. yield return typeof(CoreAppHost).Assembly;
  107. // Jellyfin.Database.Implementations
  108. yield return typeof(JellyfinDbContext).Assembly;
  109. // Jellyfin.Server.Implementations
  110. yield return typeof(ServiceCollectionExtensions).Assembly;
  111. // Jellyfin.LiveTv
  112. yield return typeof(LiveTvManager).Assembly;
  113. }
  114. }
  115. }