CoreAppHost.cs 4.9 KB

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