static void Main(string[] args) { var container = new DIContainer(); container.Register(typeof(Bread), typeof(SesameSeedBun)); container.Register(typeof(Cheese), typeof(SwissCheese)); container.Register(typeof(Sauce), typeof(Ketchup)); container.Register(typeof(Patty), typeof(ChickenPatty)); var burger = container.Build(typeof(Burger)); Console.ReadKey(true); }
public static DIContainer Register <TContract, TImpl>(this DIContainer container, string name = null) where TImpl : TContract { container.Register(typeof(TContract), typeof(TImpl), name); return(container); }