public void AddComponentInstance()
		{
			CustomerImpl customer = new CustomerImpl();
		    kernel.Register(Component.For<ICustomer>().Named("key").Instance(customer));
			Assert.IsTrue(kernel.HasComponent("key"));

			CustomerImpl customer2 = kernel.Resolve("key", new Arguments()) as CustomerImpl;
			Assert.AreSame(customer, customer2);

			customer2 = kernel.Resolve<ICustomer>() as CustomerImpl;
			Assert.AreSame(customer, customer2);
		}
Пример #2
0
		public void AddComponentInstance()
		{
			var customer = new CustomerImpl();
			Kernel.Register(Component.For<ICustomer>().Named("key").Instance(customer));
			Assert.IsTrue(Kernel.HasComponent("key"));

			var customer2 = Kernel.Resolve<CustomerImpl>("key");
			Assert.AreSame(customer, customer2);

			customer2 = Kernel.Resolve<ICustomer>() as CustomerImpl;
			Assert.AreSame(customer, customer2);
		}
Пример #3
0
		public void AddComponentInstance()
		{
			CustomerImpl customer = new CustomerImpl();

			kernel.AddComponentInstance("key", typeof(ICustomer), customer);
			Assert.IsTrue(kernel.HasComponent("key"));

			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()
		{
			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);
		}
Пример #5
0
		public void AddComponentInstance_ByService()
		{
			var customer = new CustomerImpl();

			Kernel.Register(Component.For<ICustomer>().Instance(customer));
			Assert.AreSame(Kernel.Resolve<ICustomer>(), customer);
		}
Пример #6
0
		public void AddComponentInstance_ByService()
		{
			CustomerImpl customer = new CustomerImpl();

			kernel.AddComponentInstance<ICustomer>(customer);
			Assert.AreSame(kernel[typeof(ICustomer)], customer);
		}
		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);
		}
Пример #8
0
		protected override object InternalCreate(CreationContext context)
		{
			CustomerImpl customer = new CustomerImpl();
			customer.Name = "James Bond";
			return customer;			
		}
		public void AddComponentInstance_ByService()
		{
			CustomerImpl customer = new CustomerImpl();

			kernel.Register(Component.For(typeof(ICustomer)).Instance(customer));
			Assert.AreSame(kernel.Resolve<ICustomer>(), customer);
		}