Exemplo n.º 1
0
		public void HandlerTest()
		{
			SimpleContainer sc = new SimpleContainer();
			ITest1 t1 = null;
			sc.Handler<ITest1>((i) =>
			{
				Assert.AreEqual(sc, i);
				t1 = new Test1();
				return t1;
			});

			var result1 = sc.GetInstance<ITest1>();
			Assert.IsNotNull(t1);
			Assert.IsNotNull(result1);
			Assert.AreEqual(t1, result1);

			Test2 t2 = null;
			sc.Handler<ITest2, Test2>(i =>
			{
				Assert.AreEqual(sc, i);
				t2 = new Test2();
				return t2;
			});

			var result2 = sc.GetInstance<ITest2>();
			Assert.IsNotNull(t2);
			Assert.IsNotNull(result2);
			Assert.AreEqual(t2, result2);

			result2 = sc.GetInstance<Test2>();
			Assert.IsNotNull(result2);
			Assert.AreEqual(t2, result2);
		}
Exemplo n.º 2
0
		public void InstanceTest()
		{
			SimpleContainer sc = new SimpleContainer();
			ITest1 ti = new Test1();
			sc.Instance<ITest1, Test1>(ti);
			var result = sc.GetInstance<ITest1>();
			Assert.AreEqual(result, ti);
			var result2 = sc.GetInstance<Test1>();
			Assert.AreEqual(result2, ti);

			Test2 t2 = new Test2();
			sc.Instance(t2);
			var result3 = sc.GetInstance<Test2>();
			Assert.AreEqual(result3, t2);

			Test3 t3 = new Tests.Test3();
			sc.Instance<ITest3>(t3);
			var result4 = sc.GetInstance<ITest3>();
			Assert.AreEqual(result4, t3);
		}