Created
October 25, 2016 15:58
-
-
Save jmoo/b76aa0d501e2b7a7eae9fbba6739d039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Container | |
{ | |
private Dictionary<Type, Object> map; | |
public Container() | |
{ | |
map = new Dictionary<Type, Object>(); | |
} | |
public void Bind<T>(Func<Container, T> lambda) | |
{ | |
map.Add(typeof(T), lambda); | |
} | |
public T Make<T>() | |
{ | |
var type = typeof(T); | |
if (!map.ContainsKey(type)) | |
{ | |
throw new NotRegisteredException(); | |
} | |
return (T) ((Func<Container, T>) map[type])(this); | |
} | |
public class NotRegisteredException : Exception { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment