CoreAppHost.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Reflection;
  5. using Emby.Drawing;
  6. using Emby.Server.Implementations;
  7. using Jellyfin.Drawing.Skia;
  8. using Jellyfin.Server.Implementations;
  9. using Jellyfin.Server.Implementations.Activity;
  10. using Jellyfin.Server.Implementations.Events;
  11. using Jellyfin.Server.Implementations.Users;
  12. using MediaBrowser.Common.Net;
  13. using MediaBrowser.Controller;
  14. using MediaBrowser.Controller.Drawing;
  15. using MediaBrowser.Controller.Events;
  16. using MediaBrowser.Controller.Library;
  17. using MediaBrowser.Model.Activity;
  18. using MediaBrowser.Model.IO;
  19. using Microsoft.EntityFrameworkCore;
  20. using Microsoft.Extensions.DependencyInjection;
  21. using Microsoft.Extensions.Logging;
  22. namespace Jellyfin.Server
  23. {
  24. /// <summary>
  25. /// Implementation of the abstract <see cref="ApplicationHost" /> class.
  26. /// </summary>
  27. public class CoreAppHost : ApplicationHost
  28. {
  29. /// <summary>
  30. /// Initializes a new instance of the <see cref="CoreAppHost" /> class.
  31. /// </summary>
  32. /// <param name="applicationPaths">The <see cref="ServerApplicationPaths" /> to be used by the <see cref="CoreAppHost" />.</param>
  33. /// <param name="loggerFactory">The <see cref="ILoggerFactory" /> to be used by the <see cref="CoreAppHost" />.</param>
  34. /// <param name="options">The <see cref="StartupOptions" /> to be used by the <see cref="CoreAppHost" />.</param>
  35. /// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param>
  36. /// <param name="networkManager">The <see cref="INetworkManager" /> to be used by the <see cref="CoreAppHost" />.</param>
  37. /// <param name="collection">The <see cref="IServiceCollection"/> to be used by the <see cref="CoreAppHost"/>.</param>
  38. public CoreAppHost(
  39. IServerApplicationPaths applicationPaths,
  40. ILoggerFactory loggerFactory,
  41. IStartupOptions options,
  42. IFileSystem fileSystem,
  43. INetworkManager networkManager,
  44. IServiceCollection collection)
  45. : base(
  46. applicationPaths,
  47. loggerFactory,
  48. options,
  49. fileSystem,
  50. networkManager,
  51. collection)
  52. {
  53. }
  54. /// <inheritdoc/>
  55. protected override void RegisterServices()
  56. {
  57. // Register an image encoder
  58. bool useSkiaEncoder = SkiaEncoder.IsNativeLibAvailable();
  59. Type imageEncoderType = useSkiaEncoder
  60. ? typeof(SkiaEncoder)
  61. : typeof(NullImageEncoder);
  62. ServiceCollection.AddSingleton(typeof(IImageEncoder), imageEncoderType);
  63. // Log a warning if the Skia encoder could not be used
  64. if (!useSkiaEncoder)
  65. {
  66. Logger.LogWarning($"Skia not available. Will fallback to {nameof(NullImageEncoder)}.");
  67. }
  68. ServiceCollection.AddDbContextPool<JellyfinDb>(
  69. options => options.UseSqlite($"Filename={Path.Combine(ApplicationPaths.DataPath, "jellyfin.db")}"));
  70. ServiceCollection.AddEventServices();
  71. ServiceCollection.AddSingleton<IEventManager, EventManager>();
  72. ServiceCollection.AddSingleton<JellyfinDbProvider>();
  73. ServiceCollection.AddSingleton<IActivityManager, ActivityManager>();
  74. ServiceCollection.AddSingleton<IUserManager, UserManager>();
  75. ServiceCollection.AddSingleton<IDisplayPreferencesManager, DisplayPreferencesManager>();
  76. base.RegisterServices();
  77. }
  78. /// <inheritdoc />
  79. protected override void RestartInternal() => Program.Restart();
  80. /// <inheritdoc />
  81. protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
  82. {
  83. // Jellyfin.Server
  84. yield return typeof(CoreAppHost).Assembly;
  85. // Jellyfin.Server.Implementations
  86. yield return typeof(JellyfinDb).Assembly;
  87. }
  88. /// <inheritdoc />
  89. protected override void ShutdownInternal() => Program.Shutdown();
  90. }
  91. }