CoreAppHost.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections.Generic;
  2. using System.Reflection;
  3. using Emby.Drawing;
  4. using Emby.Server.Implementations;
  5. using Jellyfin.Drawing.Skia;
  6. using MediaBrowser.Common.Net;
  7. using MediaBrowser.Controller.Drawing;
  8. using MediaBrowser.Model.IO;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using Microsoft.Extensions.Logging;
  11. namespace Jellyfin.Server
  12. {
  13. /// <summary>
  14. /// Implementation of the abstract <see cref="ApplicationHost" /> class.
  15. /// </summary>
  16. public class CoreAppHost : ApplicationHost
  17. {
  18. /// <summary>
  19. /// Initializes a new instance of the <see cref="CoreAppHost" /> class.
  20. /// </summary>
  21. /// <param name="applicationPaths">The <see cref="ServerApplicationPaths" /> to be used by the <see cref="CoreAppHost" />.</param>
  22. /// <param name="loggerFactory">The <see cref="ILoggerFactory" /> to be used by the <see cref="CoreAppHost" />.</param>
  23. /// <param name="options">The <see cref="StartupOptions" /> to be used by the <see cref="CoreAppHost" />.</param>
  24. /// <param name="fileSystem">The <see cref="IFileSystem" /> to be used by the <see cref="CoreAppHost" />.</param>
  25. /// <param name="networkManager">The <see cref="INetworkManager" /> to be used by the <see cref="CoreAppHost" />.</param>
  26. public CoreAppHost(
  27. ServerApplicationPaths applicationPaths,
  28. ILoggerFactory loggerFactory,
  29. StartupOptions options,
  30. IFileSystem fileSystem,
  31. INetworkManager networkManager)
  32. : base(
  33. applicationPaths,
  34. loggerFactory,
  35. options,
  36. fileSystem,
  37. networkManager)
  38. {
  39. }
  40. /// <inheritdoc/>
  41. protected override void RegisterServices(IServiceCollection serviceCollection)
  42. {
  43. var imageEncoderType = SkiaEncoder.IsNativeLibAvailable()
  44. ? typeof(SkiaEncoder)
  45. : typeof(NullImageEncoder);
  46. serviceCollection.AddSingleton(typeof(IImageEncoder), imageEncoderType);
  47. base.RegisterServices(serviceCollection);
  48. }
  49. /// <inheritdoc />
  50. protected override void RestartInternal() => Program.Restart();
  51. /// <inheritdoc />
  52. protected override IEnumerable<Assembly> GetAssembliesWithPartsInternal()
  53. {
  54. yield return typeof(CoreAppHost).Assembly;
  55. }
  56. /// <inheritdoc />
  57. protected override void ShutdownInternal() => Program.Shutdown();
  58. }
  59. }