public void AddComponent_Instance_UsesInstance() { CustomerImpl customer = new CustomerImpl(); Kernel.Register( Component.For<ICustomer>() .Named("key") .Instance(customer) ); Assert.IsTrue(Kernel.HasComponent("key")); IHandler handler = Kernel.GetHandler("key"); Assert.AreEqual(customer.GetType(), handler.ComponentModel.Implementation); CustomerImpl customer2 = Kernel["key"] as CustomerImpl; Assert.AreSame(customer, customer2); customer2 = Kernel[typeof(ICustomer)] as CustomerImpl; Assert.AreSame(customer, customer2); }
public void AddComponent_Instance_UsesInstance() { var customer = new CustomerImpl(); Kernel.Register( Component.For<ICustomer>() .Named("key") .Instance(customer) ); Assert.IsTrue(Kernel.HasComponent("key")); var handler = Kernel.GetHandler("key"); Assert.AreEqual(customer.GetType(), handler.ComponentModel.Implementation); var customer2 = Kernel.Resolve("key", new Arguments()) as CustomerImpl; Assert.AreSame(customer, customer2); customer2 = Kernel.Resolve<ICustomer>() as CustomerImpl; Assert.AreSame(customer, customer2); }