CoreAppHost.cs 5.8 KB

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