Add Dependency Map, Update Assembly Crawler

[Untested] Assembly Crawler will now accept constructors matching: new(), new(CommandService), new(IDependencyMap).

Add IDependencyMap

Add DependencyMap
This commit is contained in:
Christopher F
2016-07-20 17:50:52 -04:00
parent 6e42acba68
commit bbe51012cf
5 changed files with 65 additions and 10 deletions

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Discord.Commands
{
public class DependencyMap : IDependencyMap
{
private Dictionary<Type, object> map;
public T Get<T>() where T : class
{
var t = typeof(T);
if (!map.ContainsKey(t))
throw new KeyNotFoundException($"The dependency map does not contain \"{t.FullName}\"");
return map[t] as T;
}
public void Add<T>(T obj)
{
var t = typeof(T);
if (map.ContainsKey(t))
throw new InvalidOperationException($"The dependency map already contains \"{t.FullName}\"");
map.Add(t, obj);
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Discord.Commands
{
public interface IDependencyMap
{
T Get<T>() where T : class;
void Add<T>(T obj);
}
}