Ejemplo n.º 1
0
 private static void CtorTransient(long series, IPerformanceCounter performanceCounter)
 {
     using (performanceCounter.Run())
     {
         for (var i = 0; i < series; i++)
         {
             CreateTransientService().DoSomething();
         }
     }
 }
Ejemplo n.º 2
0
        private static void CtorSingleton(long series, IPerformanceCounter performanceCounter)
        {
            lock (LockObject)
            {
                _service2 = null;
            }

            using (performanceCounter.Run())
            {
                for (var i = 0; i < series; i++)
                {
                    CreateSingletonService().DoSomething();
                }
            }
        }
Ejemplo n.º 3
0
 private static void ThisTransient(long series, IPerformanceCounter performanceCounter)
 {
     using (var container = ThisContainer.CreateCore())
         using (container.Bind <IService1>().To <Service1>())
             using (container.Bind <IService2>().To <Service2>())
                 using (container.Bind <IService3>().To <Service3>())
                     using (container.Bind <IService4>().To <Service4>())
                     {
                         using (performanceCounter.Run())
                         {
                             for (var i = 0; i < series; i++)
                             {
                                 container.Resolve <IService1>().DoSomething();
                             }
                         }
                     }
 }
Ejemplo n.º 4
0
        private static void AutofacTransient(long series, IPerformanceCounter performanceCounter)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <Service1>().As <IService1>();
            builder.RegisterType <Service2>().As <IService2>();
            builder.RegisterType <Service3>().As <IService3>();
            builder.RegisterType <Service4>().As <IService4>();
            using (var container = builder.Build())
                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        container.Resolve <IService1>().DoSomething();
                    }
                }
        }
Ejemplo n.º 5
0
 private static void DryIocTransient(long series, IPerformanceCounter performanceCounter)
 {
     using (var container = new Container())
     {
         container.Register <IService1, Service1>();
         container.Register <IService2, Service2>();
         container.Register <IService3, Service3>();
         container.Register <IService4, Service4>();
         using (performanceCounter.Run())
         {
             for (var i = 0; i < series; i++)
             {
                 container.Resolve <IService1>().DoSomething();
             }
         }
     }
 }
Ejemplo n.º 6
0
 private static void LightInjectSingleton(long series, IPerformanceCounter performanceCounter)
 {
     using (var container = new ServiceContainer())
     {
         container.Register <IService1, Service1>();
         container.Register <IService2, Service2>(new PerContainerLifetime());
         container.Register <IService3, Service3>();
         container.Register <IService4, Service4>();
         using (performanceCounter.Run())
         {
             for (var i = 0; i < series; i++)
             {
                 container.GetInstance <IService1>().DoSomething();
             }
         }
     }
 }
Ejemplo n.º 7
0
 private static void CastleWindsorTransient(long series, IPerformanceCounter performanceCounter)
 {
     using (var container = new WindsorContainer())
     {
         container.Register(Component.For <IService1>().ImplementedBy <Service1>().LifestyleTransient());
         container.Register(Component.For <IService2>().ImplementedBy <Service2>().LifestyleTransient());
         container.Register(Component.For <IService3>().ImplementedBy <Service3>().LifestyleTransient());
         container.Register(Component.For <IService4>().ImplementedBy <Service4>().LifestyleTransient());
         using (performanceCounter.Run())
         {
             for (var i = 0; i < series; i++)
             {
                 container.Resolve <IService1>().DoSomething();
             }
         }
     }
 }
Ejemplo n.º 8
0
 private static void NinjectTransient(long series, IPerformanceCounter performanceCounter)
 {
     using (var kernel = new StandardKernel())
     {
         kernel.Bind <IService1>().To <Service1>();
         kernel.Bind <IService2>().To <Service2>();
         kernel.Bind <IService3>().To <Service3>();
         kernel.Bind <IService4>().To <Service4>();
         using (performanceCounter.Run())
         {
             for (var i = 0; i < series; i++)
             {
                 kernel.Get <IService1>().DoSomething();
             }
         }
     }
 }
Ejemplo n.º 9
0
 private static void UnityTransient(long series, IPerformanceCounter performanceCounter)
 {
     using (var container = new UnityContainer())
     {
         container.RegisterType <IService1, Service1>();
         container.RegisterType <IService2, Service2>(new ContainerControlledLifetimeManager());
         container.RegisterType <IService3, Service3>();
         container.RegisterType <IService4, Service4>();
         using (performanceCounter.Run())
         {
             for (var i = 0; i < series; i++)
             {
                 container.Resolve <IService1>().DoSomething();
             }
         }
     }
 }
Ejemplo n.º 10
0
        private static void AutofacComplex(long series, IPerformanceCounter performanceCounter)
        {
            var builder = new ContainerBuilder();

            foreach (var type in TestTypeBuilder.Types)
            {
                builder.RegisterType(type).As(type);
            }

            using (var container = builder.Build())
                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        container.Resolve(TestTypeBuilder.RootType);
                    }
                }
        }
Ejemplo n.º 11
0
        private static void DryIocComplex(long series, IPerformanceCounter performanceCounter)
        {
            using (var container = new Container())
            {
                foreach (var type in TestTypeBuilder.Types)
                {
                    container.Register(type);
                }

                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        container.Resolve(TestTypeBuilder.RootType);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private static void LightInjectComplex(long series, IPerformanceCounter performanceCounter)
        {
            using (var container = new ServiceContainer())
            {
                foreach (var type in TestTypeBuilder.Types)
                {
                    container.Register(type);
                }

                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        container.GetInstance(TestTypeBuilder.RootType);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private static void CastleWindsorComplex(long series, IPerformanceCounter performanceCounter)
        {
            using (var container = new WindsorContainer())
            {
                foreach (var type in TestTypeBuilder.Types)
                {
                    container.Register(Component.For(type).ImplementedBy(type).LifestyleTransient());
                }

                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        container.Resolve(TestTypeBuilder.RootType);
                    }
                }
            }
        }
Ejemplo n.º 14
0
        private static void ThisComplex(long series, IPerformanceCounter performanceCounter)
        {
            using (var container = ThisContainer.CreateCore())
            {
                foreach (var type in TestTypeBuilder.Types)
                {
                    container.Bind(type).To(type);
                }

                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        container.Resolve <object>(TestTypeBuilder.RootType);
                    }
                }
            }
        }
Ejemplo n.º 15
0
        private static void NinjectComplex(long series, IPerformanceCounter performanceCounter)
        {
            using (var kernel = new StandardKernel())
            {
                foreach (var type in TestTypeBuilder.Types)
                {
                    kernel.Bind(type).To(type);
                }

                using (performanceCounter.Run())
                {
                    for (var i = 0; i < series; i++)
                    {
                        kernel.Get(TestTypeBuilder.RootType);
                    }
                }
            }
        }
Ejemplo n.º 16
0
        private static void ThisByFuncTransient(long series, IPerformanceCounter performanceCounter)
        {
            var emptyArgs = new object[0];

            using (var container = ThisContainer.CreateCore())
                using (container.Bind <IService1>().To <Service1>())
                    using (container.Bind <IService2>().To <Service2>())
                        using (container.Bind <IService3>().To <Service3>())
                            using (container.Bind <IService4>().To <Service4>())
                            {
                                using (performanceCounter.Run())
                                {
                                    container.TryGetResolver <IService1>(typeof(IService1), null, out var resolver, out _);
                                    for (var i = 0; i < series; i++)
                                    {
                                        resolver(container, emptyArgs).DoSomething();
                                    }
                                }
                            }
        }
Ejemplo n.º 17
0
        private static void ThisByFuncComplex(long series, IPerformanceCounter performanceCounter)
        {
            var emptyArgs = new object[0];

            using (var container = ThisContainer.CreateCore())
            {
                foreach (var type in TestTypeBuilder.Types)
                {
                    container.Bind(type).To(type);
                }

                using (performanceCounter.Run())
                {
                    container.TryGetResolver <object>(TestTypeBuilder.RootType, null, out var resolver, out _);
                    for (var i = 0; i < series; i++)
                    {
                        resolver(container, emptyArgs);
                    }
                }
            }
        }