static void ChainingInjection() { Console.Write("Straight:\t"); watch.Start(); for(int i = 0; i < n; ++i) { var c = new TestClass1(); var d = new TestClass2(c); var e = new TestClass3(d); var f = new TestClass4(e); } watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); Console.Write("pooDI:\t\t"); watch.Start(); var pooDI = new DI.Container(); pooDI.RegisterType<ITestClass1, TestClass1>(false); pooDI.RegisterType<TestClass2>(false); pooDI.RegisterType<TestClass3>(false); pooDI.RegisterType<TestClass4>(false); for(int i = 0; i < n; ++i) { var c = pooDI.Resolve<TestClass4>(); } watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); Console.Write("Unity:\t\t"); watch.Start(); var unity = new UnityContainer(); unity.RegisterType<ITestClass1, TestClass1>(); unity.RegisterType<TestClass2>(); unity.RegisterType<TestClass3>(); unity.RegisterType<TestClass4>(); for(int i = 0; i < n; ++i) { var c = unity.Resolve<TestClass4>(); } watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); Console.Write("Ninject:\t"); watch.Start(); var kernel = new StandardKernel(); kernel.Bind<ITestClass1>().To<TestClass1>(); kernel.Bind<TestClass2>().ToSelf(); kernel.Bind<TestClass3>().ToSelf(); kernel.Bind<TestClass4>().ToSelf(); for(int i = 0; i < n; ++i) { var c = kernel.Get<TestClass4>(); } watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); Console.Write("Autofac:\t"); watch.Start(); var builder = new ContainerBuilder(); builder.RegisterType<TestClass1>().As<ITestClass1>(); builder.RegisterType<TestClass2>().AsSelf(); builder.RegisterType<TestClass3>().AsSelf(); builder.RegisterType<TestClass4>().AsSelf(); var container = builder.Build(); for(int i = 0; i < n; ++i) { var c = container.Resolve<TestClass4>(); } watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); Console.Write("Castle Windsor:\t"); watch.Start(); var windsor = new WindsorContainer(); windsor.Register( Component.For<ITestClass1>() .ImplementedBy<TestClass1>() .LifestyleTransient(), Component.For<TestClass2>() .LifestyleTransient(), Component.For<TestClass3>() .LifestyleTransient(), Component.For<TestClass4>() .LifestyleTransient() ); for(int i = 0; i < n; ++i) { var c = windsor.Resolve<TestClass4>(); windsor.Release(c); } watch.Stop(); Console.WriteLine(watch.Elapsed); watch.Reset(); }
public TestClass4(TestClass3 t) { this.t = t; }