diff --git a/src/Discord.Net.Commands/Attributes/InjectAttribute.cs b/src/Discord.Net.Commands/Attributes/InjectAttribute.cs index 836a4c668..09c0b553b 100644 --- a/src/Discord.Net.Commands/Attributes/InjectAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/InjectAttribute.cs @@ -2,6 +2,12 @@ namespace Discord.Commands { + /// + /// Indicates that this property should be filled in by dependency injection. + /// + /// + /// This property **MUST** have a setter. + /// [AttributeUsage(AttributeTargets.Property)] public sealed class InjectAttribute : Attribute { diff --git a/src/Discord.Net.Commands/Dependencies/DependencyMap.cs b/src/Discord.Net.Commands/Dependencies/DependencyMap.cs index 7f489fda0..0761f5fff 100644 --- a/src/Discord.Net.Commands/Dependencies/DependencyMap.cs +++ b/src/Discord.Net.Commands/Dependencies/DependencyMap.cs @@ -14,14 +14,18 @@ namespace Discord.Commands map = new Dictionary>(); } + /// public void Add(T obj) where T : class => AddFactory(() => obj); + /// public void AddTransient() where T : class, new() => AddFactory(() => new T()); + /// public void AddTransient() where TKey : class where TImpl : class, TKey, new() => AddFactory(() => new TImpl()); - + + /// public void AddFactory(Func factory) where T : class { var t = typeof(T); @@ -30,10 +34,12 @@ namespace Discord.Commands map.Add(t, factory); } + /// public T Get() { return (T)Get(typeof(T)); } + /// public object Get(Type t) { object result; @@ -43,6 +49,7 @@ namespace Discord.Commands return result; } + /// public bool TryGet(out T result) { object untypedResult; @@ -57,6 +64,7 @@ namespace Discord.Commands return false; } } + /// public bool TryGet(Type t, out object result) { Func func; diff --git a/src/Discord.Net.Commands/Dependencies/IDependencyMap.cs b/src/Discord.Net.Commands/Dependencies/IDependencyMap.cs index aab94156b..fb042c304 100644 --- a/src/Discord.Net.Commands/Dependencies/IDependencyMap.cs +++ b/src/Discord.Net.Commands/Dependencies/IDependencyMap.cs @@ -4,15 +4,59 @@ namespace Discord.Commands { public interface IDependencyMap { + /// + /// Add an instance of a service to be injected. + /// + /// The type of service. + /// The instance of a service. void Add(T obj) where T : class; + /// + /// Add a service that will be injected by a new instance every time. + /// + /// The type of instance to inject. void AddTransient() where T : class, new(); + /// + /// Add a service that will be injected by a new instance every time. + /// + /// The type to look for when injecting. + /// The type to inject when injecting. + /// + /// map.AddTransient<IService, Service> + /// void AddTransient() where TKey: class where TImpl : class, TKey, new(); + /// + /// Add a service that will be injected by a factory. + /// + /// The type to look for when injecting. + /// The factory that returns a type of this service. void AddFactory(Func factory) where T : class; + /// + /// Pull an object from the map. + /// + /// The type of service. + /// An instance of this service. T Get(); + /// + /// Try to pull an object from the map. + /// + /// The type of service. + /// The instance of this service. + /// Whether or not this object could be found in the map. bool TryGet(out T result); + /// + /// Pull an object from the map. + /// + /// The type of service. + /// An instance of this service. object Get(Type t); + /// + /// Try to pull an object from the map. + /// + /// The type of service. + /// An instance of this service. + /// Whether or not this object could be found in the map. bool TryGet(Type t, out object result); } }