IApplicationHost.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 changes requiring a restart.
  34. /// </summary>
  35. /// <value><c>true</c> if this instance has a pending restart; otherwise, <c>false</c>.</value>
  36. bool HasPendingRestart { get; }
  37. /// <summary>
  38. /// Gets or sets a value indicating whether the application should restart.
  39. /// </summary>
  40. bool ShouldRestart { get; set; }
  41. /// <summary>
  42. /// Gets the application version.
  43. /// </summary>
  44. /// <value>The application version.</value>
  45. Version ApplicationVersion { get; }
  46. /// <summary>
  47. /// Gets or sets the service provider.
  48. /// </summary>
  49. IServiceProvider? ServiceProvider { get; set; }
  50. /// <summary>
  51. /// Gets the application version.
  52. /// </summary>
  53. /// <value>The application version.</value>
  54. string ApplicationVersionString { get; }
  55. /// <summary>
  56. /// Gets the application user agent.
  57. /// </summary>
  58. /// <value>The application user agent.</value>
  59. string ApplicationUserAgent { get; }
  60. /// <summary>
  61. /// Gets the email address for use within a comment section of a user agent field.
  62. /// Presently used to provide contact information to MusicBrainz service.
  63. /// </summary>
  64. string ApplicationUserAgentAddress { get; }
  65. /// <summary>
  66. /// Gets all plugin assemblies which implement a custom rest api.
  67. /// </summary>
  68. /// <returns>An <see cref="IEnumerable{Assembly}"/> containing the plugin assemblies.</returns>
  69. IEnumerable<Assembly> GetApiPluginAssemblies();
  70. /// <summary>
  71. /// Notifies the pending restart.
  72. /// </summary>
  73. void NotifyPendingRestart();
  74. /// <summary>
  75. /// Gets the exports.
  76. /// </summary>
  77. /// <typeparam name="T">The type.</typeparam>
  78. /// <param name="manageLifetime">If set to <c>true</c> [manage lifetime].</param>
  79. /// <returns><see cref="IReadOnlyCollection{T}" />.</returns>
  80. IReadOnlyCollection<T> GetExports<T>(bool manageLifetime = true);
  81. /// <summary>
  82. /// Gets the exports.
  83. /// </summary>
  84. /// <typeparam name="T">The type.</typeparam>
  85. /// <param name="defaultFunc">Delegate function that gets called to create the object.</param>
  86. /// <param name="manageLifetime">If set to <c>true</c> [manage lifetime].</param>
  87. /// <returns><see cref="IReadOnlyCollection{T}" />.</returns>
  88. IReadOnlyCollection<T> GetExports<T>(CreationDelegateFactory defaultFunc, bool manageLifetime = true);
  89. /// <summary>
  90. /// Gets the export types.
  91. /// </summary>
  92. /// <typeparam name="T">The type.</typeparam>
  93. /// <returns>IEnumerable{Type}.</returns>
  94. IEnumerable<Type> GetExportTypes<T>();
  95. /// <summary>
  96. /// Resolves this instance.
  97. /// </summary>
  98. /// <typeparam name="T">The <c>Type</c>.</typeparam>
  99. /// <returns>``0.</returns>
  100. T Resolve<T>();
  101. /// <summary>
  102. /// Initializes this instance.
  103. /// </summary>
  104. /// <param name="serviceCollection">Instance of the <see cref="IServiceCollection"/> interface.</param>
  105. void Init(IServiceCollection serviceCollection);
  106. }
  107. }