IApplicationHost.cs 4.7 KB

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