You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

IDependencyMap.cs 2.6 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. namespace Discord.Commands
  3. {
  4. public interface IDependencyMap
  5. {
  6. /// <summary>
  7. /// Add an instance of a service to be injected.
  8. /// </summary>
  9. /// <typeparam name="T">The type of service.</typeparam>
  10. /// <param name="obj">The instance of a service.</param>
  11. void Add<T>(T obj) where T : class;
  12. /// <summary>
  13. /// Add a service that will be injected by a new instance every time.
  14. /// </summary>
  15. /// <typeparam name="T">The type of instance to inject.</typeparam>
  16. void AddTransient<T>() where T : class, new();
  17. /// <summary>
  18. /// Add a service that will be injected by a new instance every time.
  19. /// </summary>
  20. /// <typeparam name="TKey">The type to look for when injecting.</typeparam>
  21. /// <typeparam name="TImpl">The type to inject when injecting.</typeparam>
  22. /// <example>
  23. /// map.AddTransient&#60;IService, Service&#62;
  24. /// </example>
  25. void AddTransient<TKey, TImpl>() where TKey: class where TImpl : class, TKey, new();
  26. /// <summary>
  27. /// Add a service that will be injected by a factory.
  28. /// </summary>
  29. /// <typeparam name="T">The type to look for when injecting.</typeparam>
  30. /// <param name="factory">The factory that returns a type of this service.</param>
  31. void AddFactory<T>(Func<T> factory) where T : class;
  32. /// <summary>
  33. /// Pull an object from the map.
  34. /// </summary>
  35. /// <typeparam name="T">The type of service.</typeparam>
  36. /// <returns>An instance of this service.</returns>
  37. T Get<T>();
  38. /// <summary>
  39. /// Try to pull an object from the map.
  40. /// </summary>
  41. /// <typeparam name="T">The type of service.</typeparam>
  42. /// <param name="result">The instance of this service.</param>
  43. /// <returns>Whether or not this object could be found in the map.</returns>
  44. bool TryGet<T>(out T result);
  45. /// <summary>
  46. /// Pull an object from the map.
  47. /// </summary>
  48. /// <param name="t">The type of service.</param>
  49. /// <returns>An instance of this service.</returns>
  50. object Get(Type t);
  51. /// <summary>
  52. /// Try to pull an object from the map.
  53. /// </summary>
  54. /// <param name="t">The type of service.</param>
  55. /// <param name="result">An instance of this service.</param>
  56. /// <returns>Whether or not this object could be found in the map.</returns>
  57. bool TryGet(Type t, out object result);
  58. }
  59. }