Skip to content

Instantly share code, notes, and snippets.

@jmoo
Created October 25, 2016 15:58
Show Gist options
  • Save jmoo/b76aa0d501e2b7a7eae9fbba6739d039 to your computer and use it in GitHub Desktop.
Save jmoo/b76aa0d501e2b7a7eae9fbba6739d039 to your computer and use it in GitHub Desktop.
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