/src/Engine/MvcTurbine/ComponentModel/IServiceLocator.cs

https://github.com/tyronegroves/mvcturbine · C# · 126 lines · 23 code · 16 blank · 87 comment · 0 complexity · 0153899f648e021934436abee9ee21fe MD5 · raw file

  1. namespace MvcTurbine.ComponentModel {
  2. using System;
  3. using System.Collections.Generic;
  4. /// <summary>
  5. /// Provides a simple interface for resolving and registering components within
  6. /// the application.
  7. /// </summary>
  8. public interface IServiceLocator : IDisposable {
  9. /// <summary>
  10. /// Resolves the service of the specified type.
  11. /// </summary>
  12. /// <typeparam name="T">Type of service to resolve.</typeparam>
  13. /// <returns>An instance of the type, null otherwise.</returns>
  14. T Resolve<T>() where T : class;
  15. /// <summary>
  16. /// Resolves the service of the specified type by the given string key.
  17. /// </summary>
  18. /// <typeparam name="T">Type of service to resolve.</typeparam>
  19. /// <param name="key">Unique key to distinguish the service.</param>
  20. /// <returns>An instance of the type, null otherwise.</returns>
  21. T Resolve<T>(string key) where T : class;
  22. /// <summary>
  23. /// Resolves the service of the specified type by the given type key.
  24. /// </summary>
  25. /// <typeparam name="T">Type of service to resolve.</typeparam>
  26. /// <param name="type">Key type of the service.</param>
  27. /// <returns>An instance of the type, null otherwise.</returns>
  28. [Obsolete("Use object Resolve(Type type)")]
  29. T Resolve<T>(Type type) where T : class;
  30. ///<summary>
  31. /// Resolves the service of the specified type by the given type key.
  32. ///</summary>
  33. ///<param name="type">Type of service to resolve.</param>
  34. ///<returns>An instance of the type, null otherwise</returns>
  35. object Resolve(Type type);
  36. /// <summary>
  37. /// Resolves the list of services of type <see cref="T"/> that are registered
  38. /// within the locator.
  39. /// </summary>
  40. /// <typeparam name="T">Type of the service to resolve.</typeparam>
  41. /// <returns>A list of service of type <see cref="T"/>, null otherwise.</returns>
  42. IList<T> ResolveServices<T>() where T : class;
  43. IList<object> ResolveServices(Type type);
  44. /// <summary>
  45. /// Creates a <see cref="IServiceRegistrar"/> to process queued
  46. /// registration of types.
  47. /// </summary>
  48. /// <returns></returns>
  49. IServiceRegistrar Batch();
  50. /// <summary>
  51. /// Registers the implemation type, <paramref name="implType"/>, with the locator under
  52. /// the <see cref="Interface"/> service type.
  53. /// </summary>
  54. /// <typeparam name="Interface">Type of the service to register.</typeparam>
  55. /// <param name="implType">Implementation type to use for registration.</param>
  56. void Register<Interface>(Type implType) where Interface : class;
  57. /// <summary>
  58. /// Registers the implemation type, <see cref="Implementation"/>, with the locator under
  59. /// the <see cref="Interface"/> service type.
  60. /// </summary>
  61. /// <typeparam name="Interface">Type of the service to register.</typeparam>
  62. /// <typeparam name="Implementation">Implementation type to use for registration.
  63. /// </typeparam>
  64. void Register<Interface, Implementation>() where Implementation : class, Interface;
  65. /// <summary>
  66. /// Registers the implemation type, <see cref="Implementation"/>, with the locator under
  67. /// the <see cref="Interface"/> service type.
  68. /// </summary>
  69. /// <typeparam name="Interface">Type of the service to register.</typeparam>
  70. /// <typeparam name="Implementation">Implementation type to use for registration.
  71. /// </typeparam>
  72. /// <param name="key">Unique key to distinguish the service.</param>
  73. void Register<Interface, Implementation>(string key)
  74. where Implementation : class, Interface;
  75. /// <summary>
  76. /// Registers the implementation type, <paramref name="type"/>, with the locator
  77. /// by the given string key.
  78. /// </summary>
  79. /// <param name="key">Unique key to distinguish the service.</param>
  80. /// <param name="type">Implementation type to use.</param>
  81. void Register(string key, Type type);
  82. /// <summary>
  83. /// Registers the implementation type, <paramref name="implType"/>, with the locator
  84. /// by the given service type, <paramref name="serviceType"/>
  85. /// </summary>
  86. /// <param name="serviceType">Type of the service to register.</param>
  87. /// <param name="implType">Implementation to associate with the service.</param>
  88. void Register(Type serviceType, Type implType);
  89. /// <summary>
  90. /// Registers the implementation type, <paramref name="implType"/>, with the locator
  91. /// by the given service type, <paramref name="serviceType"/>
  92. /// </summary>
  93. /// <param name="serviceType">Type of the service to register.</param>
  94. /// <param name="implType">Implementation to associate with the service.</param>
  95. /// <param name="key">Unique key to distinguish the service.</param>
  96. void Register(Type serviceType, Type implType, string key);
  97. /// <summary>
  98. /// Registers the instance of type, <typeparamref name="Interface"/>, with the locator.
  99. /// </summary>
  100. /// <typeparam name="Interface">Type of the service to register.</typeparam>
  101. /// <param name="instance">Instance of the type to register.</param>
  102. void Register<Interface>(Interface instance) where Interface : class;
  103. /// <summary>
  104. /// Resolves the service of the specified interface with the provided factory method.
  105. /// </summary>
  106. /// <param name="factoryMethod">The factory method which will be used to resolve this interface.</param>
  107. /// <returns>An instance of the type, null otherwise</returns>
  108. void Register<Interface>(Func<Interface> factoryMethod) where Interface : class;
  109. }
  110. }