Beispiel #1
0
        public void It_works_with_specific_object_builder(int iterations)
        {
            IContainer builder = new NinjectObjectBuilder();

            builder.Configure(typeof(InstancePerCallComponent), DependencyLifecycle.SingleInstance);

            GC.Collect();
            var before = GC.GetTotalMemory(true);
            var sw     = Stopwatch.StartNew();

            for (var i = 0; i < iterations; i++)
            {
                using (var nestedContainer = builder.BuildChildContainer())
                {
                    nestedContainer.Build(typeof(InstancePerCallComponent));
                }
            }

            sw.Stop();
            // Collect all generations of memory.
            GC.Collect();

            var after = GC.GetTotalMemory(true);

            Console.WriteLine("{0} reps: {1} Time: {2} MemDelta: {3} bytes", iterations, builder.GetType().Name, sw.Elapsed, after - before);
        }
Beispiel #2
0
        private static IObjectBuilder BootstrapContainer()
        {
            StandardKernel kernel = new StandardKernel();
            NinjectObjectBuilder container = new NinjectObjectBuilder(kernel);
            PlaySubscriberMassTransitModel module = new PlaySubscriberMassTransitModel(container);
            kernel.Load(module);

            return container;
        }
        public void Externally_owned_container_should_not_be_disposed()
        {
            var kernel = new StandardKernel();

            var container = new NinjectObjectBuilder(kernel, false);

            container.Dispose();

            Assert.False(kernel.IsDisposed);
        }
        public void Owned_container_should_be_disposed()
        {
            var kernel = new StandardKernel();

            var container = new NinjectObjectBuilder(kernel, true);

            container.Dispose();

            Assert.True(kernel.IsDisposed);
        }