Пример #1
0
            public void Base()
            {
                IDependencyContainer root = new SimpleDependencyContainer();

                IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

                using (ITypeExecutorService executorService = reflectionService.PrepareTypeExecutors())
                {
                    executorService.AddQueryHandlers(root);
                }

                IQueryHandler <Q1, R1> handler1 = root.Resolve <IQueryHandler <Q1, R1> >();
                IQueryHandler <Q2, R2> handler2 = root.Resolve <IQueryHandler <Q2, R2> >();
            }
        public void AutoWireConverters()
        {
            IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

            using (ITypeExecutorService executors = reflectionService.PrepareTypeExecutors())
            {
                executors.AddConverters();
            }

            string value;

            Assert.AreEqual(true, Converts.Repository.TryConvert <int, string>(5, out value));
            Assert.AreEqual("5", value);
        }
        public void BaseComposition()
        {
            StringBuilder result = new StringBuilder();

            IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

            using (ITypeExecutorService executors = reflectionService.PrepareTypeExecutors())
            {
                executors.AddFiltered(true)
                .AddFilterNotInterface()
                .AddFilterNotAbstract()
                .AddHandler(t => result.AppendLine(t.FullName));
            }

            File.WriteAllText("C:/Temp/Files.txt", result.ToString());
        }
Пример #4
0
            public void ConcreteType()
            {
                IQueryHandlerCollection collection = new DefaultQueryDispatcher();

                IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

                using (ITypeExecutorService executorService = reflectionService.PrepareTypeExecutors())
                {
                    executorService.AddQueryHandlers(collection);
                }

                IQueryHandler <Q3, R3> handler3;

                Assert.AreEqual(true, collection.TryGet(out handler3));
                IQueryHandler <Q4, R4> handler4;

                Assert.AreEqual(false, collection.TryGet(out handler4));
            }
Пример #5
0
            public void Base()
            {
                IQueryHandlerCollection collection = new DefaultQueryDispatcher();

                IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

                using (ITypeExecutorService executorService = reflectionService.PrepareTypeExecutors())
                {
                    executorService.AddQueryHandlers(collection);
                }

                IQueryHandler <Q1, R1> handler1;

                Assert.AreEqual(true, collection.TryGet(out handler1));
                IQueryHandler <Q2, R2> handler2;

                Assert.AreEqual(true, collection.TryGet(out handler2));
            }
        public void AttributeFiltering()
        {
            IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

            int matchCount = 0;

            using (ITypeExecutorService executors = reflectionService.PrepareTypeExecutors())
            {
                executors.AddFiltered(false)
                .AddFilterHasAttribute <ConverterAttribute>()
                .AddHandler(t =>
                {
                    Assert.AreEqual(typeof(IntToStringConverter), t);
                    matchCount++;
                });
            }

            Assert.AreEqual(1, matchCount);
        }
        public void AbstractFiltering()
        {
            IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

            int matchCount = 0;

            using (ITypeExecutorService executors = reflectionService.PrepareTypeExecutors())
            {
                executors.AddFiltered(false)
                .AddFilterNotAbstract()
                .AddHandler(t =>
                {
                    Assert.AreEqual(false, t.IsAbstract);
                    matchCount++;
                });
            }

            Ensure.Positive(matchCount, "matchCount");
        }
Пример #8
0
            public void ConcreteType()
            {
                IDependencyContainer root = new SimpleDependencyContainer();

                IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

                using (ITypeExecutorService executorService = reflectionService.PrepareTypeExecutors())
                {
                    executorService.AddQueryHandlers(root);
                }

                IQueryHandler <Q3, R3> handler1 = root.Resolve <IQueryHandler <Q3, R3> >();

                try
                {
                    IQueryHandler <Q4, R4> handler2 = root.Resolve <IQueryHandler <Q4, R4> >();
                    Assert.Fail("Handler for Q4 should not be registered");
                }
                catch (DependencyRegistrationFailedException)
                { }
            }
Пример #9
0
        public void Base()
        {
            IDependencyContainer root = new SimpleDependencyContainer();

            IReflectionService reflectionService = ReflectionFactory.FromCurrentAppDomain();

            using (ITypeExecutorService executorService = reflectionService.PrepareTypeExecutors())
            {
                executorService.AddDependencies(root);
            }

            root.Resolve <IOutputWriter>();

            using (IDependencyProvider s1 = root.Scope("S1"))
            {
                s1.Resolve <Counter>();
                s1.Resolve <Counter>();
                s1.Resolve <Counter>();

                Assert.AreEqual(1, Counter.count);
            }
        }