CoreAppHost.cs 5.4 KB

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