Improve DI system

This commit is contained in:
Finite Reality
2016-07-21 00:23:49 +01:00
parent e266fa8b32
commit f7455c389b
5 changed files with 40 additions and 28 deletions

View File

@@ -13,12 +13,16 @@ namespace Discord.Commands
map = new Dictionary<Type, object>();
}
public T Get<T>() where T : class
public object Get(Type t)
{
var t = typeof(T);
if (!map.ContainsKey(t))
throw new KeyNotFoundException($"The dependency map does not contain \"{t.FullName}\"");
return map[t] as T;
return map[t];
}
public T Get<T>() where T : class
{
return Get(typeof(T)) as T;
}
public void Add<T>(T obj)

View File

@@ -7,6 +7,7 @@ namespace Discord.Commands
{
public interface IDependencyMap
{
object Get(Type t);
T Get<T>() where T : class;
void Add<T>(T obj);
}