IApplicationHost.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using Microsoft.Extensions.DependencyInjection;
  5. namespace MediaBrowser.Common
  6. {
  7. /// <summary>
  8. /// Delegate used with GetExports{T}.
  9. /// </summary>
  10. /// <param name="type">Type to create.</param>
  11. /// <returns>New instance of type <param>type</param>.</returns>
  12. public delegate object? CreationDelegateFactory(Type type);
  13. /// <summary>
  14. /// An interface to be implemented by the applications hosting a kernel.
  15. /// </summary>
  16. public interface IApplicationHost
  17. {
  18. /// <summary>
  19. /// Occurs when [has pending restart changed].
  20. /// </summary>
  21. event EventHandler? HasPendingRestartChanged;
  22. /// <summary>
  23. /// Gets the name.
  24. /// </summary>
  25. /// <value>The name.</value>
  26. string Name { get; }
  27. /// <summary>
  28. /// Gets the device identifier.
  29. /// </summary>
  30. /// <value>The device identifier.</value>
  31. string SystemId { get; }
  32. /// <summary>
  33. /// Gets a value indicating whether this instance has pending kernel reload.
  34. /// </summary>
  35. /// <value><c>true</c> if this instance has pending kernel reload; otherwise, <c>false</c>.</value>
  36. bool HasPendingRestart { get; }
  37. /// <summary>
  38. /// Gets a value indicating whether this instance is currently shutting down.
  39. /// </summary>
  40. /// <value><c>true</c> if this instance is shutting down; otherwise, <c>false</c>.</value>
  41. bool IsShuttingDown { get; }
  42. /// <summary>
  43. /// Gets a value indicating whether the application should restart.
  44. /// </summary>
  45. bool ShouldRestart { get; }
  46. /// <summary>
  47. /// Gets the application version.
  48. /// </summary>
  49. /// <value>The application version.</value>
  50. Version ApplicationVersion { get; }
  51. /// <summary>
  52. /// Gets or sets the service provider.
  53. /// </summary>
  54. IServiceProvider? ServiceProvider { get; set; }
  55. /// <summary>
  56. /// Gets the application version.
  57. /// </summary>
  58. /// <value>The application version.</value>
  59. string ApplicationVersionString { get; }
  60. /// <summary>
  61. /// Gets the application user agent.
  62. /// </summary>
  63. /// <value>The application user agent.</value>
  64. string ApplicationUserAgent { get; }
  65. /// <summary>
  66. /// Gets the email address for use within a comment section of a user agent field.
  67. /// Presently used to provide contact information to MusicBrainz service.
  68. /// </summary>
  69. string ApplicationUserAgentAddress { get; }
  70. /// <summary>
  71. /// Gets all plugin assemblies which implement a custom rest api.
  72. /// </summary>
  73. /// <returns>An <see cref="IEnumerable{Assembly}"/> containing the plugin assemblies.</returns>
  74. IEnumerable<Assembly> GetApiPluginAssemblies();
  75. /// <summary>
  76. /// Notifies the pending restart.
  77. /// </summary>
  78. void NotifyPendingRestart();
  79. /// <summary>
  80. /// Restarts this instance.
  81. /// </summary>
  82. void Restart();
  83. /// <summary>
  84. /// Gets the exports.
  85. /// </summary>
  86. /// <typeparam name="T">The type.</typeparam>
  87. /// <param name="manageLifetime">If set to <c>true</c> [manage lifetime].</param>
  88. /// <returns><see cref="IReadOnlyCollection{T}" />.</returns>
  89. IReadOnlyCollection<T> GetExports<T>(bool manageLifetime = true);
  90. /// <summary>
  91. /// Gets the exports.
  92. /// </summary>
  93. /// <typeparam name="T">The type.</typeparam>
  94. /// <param name="defaultFunc">Delegate function that gets called to create the object.</param>
  95. /// <param name="manageLifetime">If set to <c>true</c> [manage lifetime].</param>
  96. /// <returns><see cref="IReadOnlyCollection{T}" />.</returns>
  97. IReadOnlyCollection<T> GetExports<T>(CreationDelegateFactory defaultFunc, bool manageLifetime = true);
  98. /// <summary>
  99. /// Gets the export types.
  100. /// </summary>
  101. /// <typeparam name="T">The type.</typeparam>
  102. /// <returns>IEnumerable{Type}.</returns>
  103. IEnumerable<Type> GetExportTypes<T>();
  104. /// <summary>
  105. /// Resolves this instance.
  106. /// </summary>
  107. /// <typeparam name="T">The <c>Type</c>.</typeparam>
  108. /// <returns>``0.</returns>
  109. T Resolve<T>();
  110. /// <summary>
  111. /// Shuts down.
  112. /// </summary>
  113. void Shutdown();
  114. /// <summary>
  115. /// Initializes this instance.
  116. /// </summary>
  117. /// <param name="serviceCollection">Instance of the <see cref="IServiceCollection"/> interface.</param>
  118. void Init(IServiceCollection serviceCollection);
  119. }
  120. }