Example #1
0
        public void Test()
        {
            var config = new HttpConfiguration();

            /*
             * Following container setup will cause process to fail to Stack Overflow exception
             *
             * Make Release build and run .exe file from command line,
             * if it does not fail you can increase threadCount and iterations  integers to increase pressure
             *
             * Reproduces https://github.com/dadhi/DryIoc/issues/139
             */
            var container = new Container(rules => rules
                                          .With(FactoryMethod.ConstructorWithResolvableArguments))
                            .WithWebApi(config);

            Registrations.RegisterTypes(container, true);

            Console.WriteLine("-- Run Stack overflow test --");

            for (int i = 0; i < 10; i++)
            {
                using (var scope = container.OpenScope(Reuse.WebRequestScopeName))
                {
                    scope.Resolve(typeof(EmailController));
                }
            }
        }
Example #2
0
        public void Test_with_UseDecorateeReuse_decorators_Examine_expression_and_the_split_graph()
        {
            var container = new Container(rules => rules
                                          .WithoutInterpretationForTheFirstResolution() // compile on the first iteration
                                          .WithUseDecorateeReuseForDecorators()
                                          .With(FactoryMethod.ConstructorWithResolvableArguments))
                            .WithWebApi(new HttpConfiguration());

            Registrations.RegisterTypes(container, false);

            using (var scope = container.OpenScope(Reuse.WebRequestScopeName))
            {
                var service = scope.Resolve(typeof(EmailController));
                Assert.IsNotNull(service);

                var expr = scope.Resolve <LambdaExpression>(typeof(EmailController));
                Assert.IsNotNull(expr);

                var code          = expr.ToCSharpString(new StringBuilder(100000), 2, true, Abbreviate).ToString();
                var nestedLambdas = code.Count(c => c == '$');

                // the number when split by `dependencyCount >= 256`
                Assert.AreEqual(67, nestedLambdas);
            }
        }
Example #3
0
        public static IContainer GetContainerForTest()
        {
            var container = new Container(rules => rules
                                          .WithoutInterpretationForTheFirstResolution()
                                          .WithoutUseInterpretation()
                                          .With(FactoryMethod.ConstructorWithResolvableArguments))
                            .WithWebApi(new HttpConfiguration());

            Registrations.RegisterTypes(container, true);

            return(container);
        }
Example #4
0
        public void Test_with_singleton_decorators()
        {
            var container = new Container(rules => rules
                .With(FactoryMethod.ConstructorWithResolvableArguments))
                .WithWebApi(new HttpConfiguration());

            Registrations.RegisterTypes(container, true);

            for (var i = 0; i < 10; i++)
                using (var scope = container.OpenScope(Reuse.WebRequestScopeName))
                    scope.Resolve(typeof(EmailController));
        }
        public static IContainer GetContainerForTest(int depth)
        {
            var container = new Container((rules) =>
                                          rules
                                          .WithDependencyDepthToSplitObjectGraph(depth)
                                          .WithoutInterpretationForTheFirstResolution()
                                          .WithoutUseInterpretation()
                                          .With(FactoryMethod.ConstructorWithResolvableArguments)
                                          ).WithWebApi(new HttpConfiguration());

            Registrations.RegisterTypes(container, true);

            return(container);
        }
Example #6
0
        public static IContainer CreateContainer()
        {
            var config    = new HttpConfiguration();
            var container = new Container(rules => rules
                                          .With(FactoryMethod.ConstructorWithResolvableArguments))
                            .WithWebApi(config);

            Registrations.RegisterTypes(container, true);
            RootContainer = container;

            Console.WriteLine("New container created:");
            Console.WriteLine();
            Console.WriteLine(container.ToString());
            Console.WriteLine();

            return(container);
        }
Example #7
0
        static void Main(string[] args)
        {
            var config = new HttpConfiguration();

            /*
             * Following container setup will cause process to fail to Stack Overflow exception
             *
             * Make Release build and run .exe file from command line,
             * if it does not fail you can increase threadCount and iterations  integers to increase pressure
             *
             * Reproduces https://github.com/dadhi/DryIoc/issues/139
             */
            var container = new Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments)).WithWebApi(config);

            Registrations.RegisterTypes(container, true);

            // The same SO exception as above with `singletonDecorators: true`
            //var container = new Container(rules => rules.With(FactoryMethod.ConstructorWithResolvableArguments)).WithWebApi(config);
            //Registrations.RegisterTypes(container, false);

            /*
             * This is another variation to run into Stack Overflow exception even when using WithoutFastExpressionCompiler -config
             * Seems like in master branches its now throwing:
             * System.InvalidOperationException: 'variable 'r' of type 'DryIoc.IResolverContext' referenced from scope '', but it is not defined'
             * previously I was able to reproduce Stack Overflow exception this way
             *
             */
            // WORKS:
            //Release mode - CPU: Core i7 8750H(12 threads), RAM: 16Gb
            //    -- Load Test Result--
            //  00:04:42.45

            //var container = new Container(rules => rules.WithoutFastExpressionCompiler().With(FactoryMethod.ConstructorWithResolvableArguments)).WithWebApi(config);
            //Registrations.RegisterTypes(container, false);


            // This setup config WORKS, but uses a lot of memory
            //Release mode - CPU: Core i7 8750H(12 threads), RAM: 16Gb
            //  --Load Test Result --
            //  00:01:27.69

            // After centralized cache and fan-keyed resolution cache
            //  00:02:54.82

            //var container = new Container(rules => rules.WithoutFastExpressionCompiler().With(FactoryMethod.ConstructorWithResolvableArguments)).WithWebApi(config);
            //Registrations.RegisterTypes(container, true);

            // Validate IoC registrations
            var results = container.Validate();

            if (results.Length > 0)
            {
                throw new Exception(results.ToString());
            }
            Console.WriteLine("No IoC Validation errors detected");

            var httpControllerType = typeof(IHttpController);

            // Get Controllers which would normally be used for routing web requests
            var controllers = Assembly.GetExecutingAssembly().GetLoadedTypes()
                              .Where((t) =>
                                     !t.IsAbstract && !t.IsInterface && !t.Name.Contains("Base") &&
                                     httpControllerType.IsAssignableFrom(t))
                              .ToArray();

            // Make sure all controllers can be resolved
            ResolveAllControllersOnce(container, controllers);

            ForceGarbageCollector();

            StartTest(controllers, container);
        }