CoreAppHost.cs 5.3 KB

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