Implimented discussed changes
This commit is contained in:
@@ -38,6 +38,8 @@ namespace Discord.Commands
|
|||||||
public void AddFactory<T>(Func<T> factory) where T : class
|
public void AddFactory<T>(Func<T> factory) where T : class
|
||||||
{
|
{
|
||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
|
if (typeof(T) == typeof(IDependencyMap) || typeof(T) == typeof(CommandService))
|
||||||
|
throw new InvalidOperationException("The dependency map cannot contain services directly added as IDependencyMap or CommandService. Only Implimentations and Derivatives are permitted");
|
||||||
if (map.ContainsKey(t))
|
if (map.ContainsKey(t))
|
||||||
throw new InvalidOperationException($"The dependency map already contains \"{t.FullName}\"");
|
throw new InvalidOperationException($"The dependency map already contains \"{t.FullName}\"");
|
||||||
map.Add(t, factory);
|
map.Add(t, factory);
|
||||||
@@ -48,6 +50,8 @@ namespace Discord.Commands
|
|||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
if (map.ContainsKey(t))
|
if (map.ContainsKey(t))
|
||||||
return false;
|
return false;
|
||||||
|
if (typeof(T) == typeof(IDependencyMap) || typeof(T) == typeof(CommandService))
|
||||||
|
throw new InvalidOperationException("The dependency map cannot contain services directly added as IDependencyMap or CommandService. Only Implimentations and Derivatives are permitted");
|
||||||
map.Add(t, factory);
|
map.Add(t, factory);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ namespace Discord.Commands
|
|||||||
{
|
{
|
||||||
if (targetType == typeof(CommandService))
|
if (targetType == typeof(CommandService))
|
||||||
arg = service;
|
arg = service;
|
||||||
else if (_dependencyTypeInfo.IsAssignableFrom(targetType.GetTypeInfo()))
|
else if (targetType == typeof(IDependencyMap) || targetType == map.GetType())
|
||||||
arg = map;
|
arg = map;
|
||||||
else
|
else
|
||||||
throw new InvalidOperationException($"Failed to create \"{baseType.FullName}\", dependency \"{targetType.Name}\" was not found.");
|
throw new InvalidOperationException($"Failed to create \"{baseType.FullName}\", dependency \"{targetType.Name}\" was not found.");
|
||||||
|
|||||||
Reference in New Issue
Block a user