示例#1
0
        public void TypesThatHaveProperty()
        {
            var test = (Func <Type, bool>)TypesThat.HaveProperty("IntValue");

            Assert.True(test(typeof(PropertyClass)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#2
0
        public void SingletonPerObjectGraph_Attribute_Test()
        {
            var container = new DependencyInjectionContainer();

            container.Configure(c => c.ExportAssemblyContaining <ExportAttributeTests>().
                                ExportAttributedTypes().
                                Where(TypesThat.AreInTheSameNamespaceAs <TestAttribute>()));

            var instance =
                container.Locate <TwoDependencyService <AttributedSingletonPerObjectGraphService, AttributedSingletonPerObjectGraphService> >();

            Assert.NotNull(instance);
            Assert.NotNull(instance.Dependency1);
            Assert.NotNull(instance.Dependency2);
            Assert.Same(instance.Dependency1, instance.Dependency2);

            var instance2 =
                container.Locate <TwoDependencyService <AttributedSingletonPerObjectGraphService, AttributedSingletonPerObjectGraphService> >();

            Assert.NotNull(instance2);
            Assert.NotNull(instance2.Dependency1);
            Assert.NotNull(instance2.Dependency2);
            Assert.Same(instance2.Dependency1, instance2.Dependency2);

            Assert.NotSame(instance.Dependency1, instance2.Dependency1);
        }
        public void ExportWrapper_With_Conditions()
        {
            var container = new DependencyInjectionContainer();

            container.Configure(c =>
            {
                c.ExportWrapper(typeof(DependentService <>))
                .As(typeof(IDependentService <>))
                .When.InjectedInto(TypesThat.EndWith("A"));

                c.ExportWrapper(typeof(OtherDependentService <>))
                .As(typeof(IDependentService <>))
                .When.InjectedInto(TypesThat.EndWith("B"));

                c.Export <BasicService>().As <IBasicService>();
            });

            var instanceA = container.Locate <DependentClassA>();

            Assert.NotNull(instanceA);
            Assert.NotNull(instanceA.Service);
            Assert.NotNull(instanceA.Service.Value);
            Assert.IsType <DependentService <IBasicService> >(instanceA.Service);

            var instanceB = container.Locate <DependentClassB>();

            Assert.NotNull(instanceB);
            Assert.NotNull(instanceB.Service);
            Assert.NotNull(instanceB.Service.Value);
            Assert.IsType <OtherDependentService <IBasicService> >(instanceB.Service);
        }
示例#4
0
        public void TypesThat_AreBasedOn_Func()
        {
            var testFunc = (Func <Type, bool>)TypesThat.AreBasedOn(type => type == typeof(IBasicService));

            Assert.True(testFunc(typeof(BasicService)));
            Assert.False(testFunc(typeof(MultipleService1)));
        }
示例#5
0
        public void TypesThat_Match()
        {
            var testFunc = (Func <Type, bool>)TypesThat.Match(t => t == typeof(DependentService <>));

            Assert.True(testFunc(typeof(DependentService <>)));
            Assert.False(testFunc(typeof(TypesThatTests)));
        }
示例#6
0
        public void ExportTypeSet_ByInterfaces_Filtered()
        {
            var container = new DependencyInjectionContainer();

            container.Configure(c =>
            {
                c.ExportAssemblyContaining <IMultipleService>().ByInterfaces(TypesThat.EndWith("MultipleService"));
            });

            var enumerable = container.Locate <IEnumerable <IMultipleService> >();

            Assert.NotNull(enumerable);

            var array = enumerable.ToArray();

            Assert.NotNull(array);
            Assert.Equal(5, array.Length);
            Assert.IsType <MultipleService1>(array[0]);
            Assert.IsType <MultipleService2>(array[1]);
            Assert.IsType <MultipleService3>(array[2]);
            Assert.IsType <MultipleService4>(array[3]);
            Assert.IsType <MultipleService5>(array[4]);

            Assert.Throws <LocateException>(() => container.Locate <IBasicService>());
        }
示例#7
0
        public void TypesThatHaveAttributeFilter()
        {
            var test = (Func <Type, bool>)TypesThat.HaveAttribute(t => t == typeof(SomeAttribute));

            Assert.True(test(typeof(AttributedClass)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#8
0
        public void TypesThatAreNotPublic()
        {
            var test = (Func <Type, bool>)TypesThat.AreNotPublic();

            Assert.False(test(typeof(TypesThatTests)));
            Assert.True(test(typeof(PrivateClass)));
        }
示例#9
0
        static Composition()
        {
            Container = new DependencyInjectionContainer();
            Container.Configure(registrationBlock =>
            {
                var toolType = typeof(Tool);
                var assembly = typeof(RectangleTool).Assembly;

                registrationBlock.Export(assembly.ExportedTypes
                                         .Where(TypesThat.AreBasedOn <Tool>())
                                         .Where(x => !x.IsAbstract))
                .ByTypes(type => new[] { toolType });

                registrationBlock.Export <UwpFilePicker>().As <IFilePicker>().Lifestyle.Singleton();
                registrationBlock.Export <DesignContext>().As <IDesignContext>().Lifestyle.Singleton();
                registrationBlock.Export <ViewModelFactory>().As <IViewModelFactory>().Lifestyle.Singleton();
                registrationBlock.Export <ProjectStore>().As <IProjectStore>().Lifestyle.Singleton();
                registrationBlock.Export <ServiceFactory>().As <IServiceFactory>().Lifestyle.Singleton();
                registrationBlock.ExportFactory((IServiceFactory factory, IFilePicker picker) => new ExtensionsProvider("superjmn.suppadesigner", factory, picker)).As <IExtensionsProvider>().Lifestyle.Singleton();
                registrationBlock.ExportFactory(
                    ((string, string)pair) => new WindowsAppService(pair.Item1, pair.Item2)).As <IDictionaryBasedService>();

                registrationBlock.Export <ProjectMapper>().As <IProjectMapper>().Lifestyle.Singleton();
                registrationBlock.Export <ImportExtensionsViewModel>().Lifestyle.Singleton();
                registrationBlock.Export <MainViewModel>().Lifestyle.Singleton();
            });
        }
示例#10
0
        public void TypesThatAreBasedOnFilter()
        {
            var test = (Func <Type, bool>)TypesThat.AreBasedOn(type => type.GetTypeInfo().BaseType == typeof(BaseClass));

            Assert.True(test(typeof(InheritClass)));
            Assert.False(test(typeof(TypesThatTests)));
        }
示例#11
0
        public void TypesThatMatch()
        {
            var test = (Func <Type, bool>)TypesThat.Match(t => t.Name.Contains("That"));

            Assert.False(test(typeof(PrivateClass)));
            Assert.True(test(typeof(TypesThatTests)));
        }
示例#12
0
        public void TypesThatAreInTheSameNamespaceAsGeneric()
        {
            var test = (Func <Type, bool>)TypesThat.AreInTheSameNamespaceAs <TypesThatTests>();

            Assert.True(test(typeof(TypesThatTests)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#13
0
        public void TypesThatAreBasedOnGeneric()
        {
            var test = (Func <Type, bool>)TypesThat.AreBasedOn <BaseClass>();

            Assert.True(test(typeof(InheritClass)));
            Assert.False(test(typeof(TypesThatTests)));
        }
示例#14
0
        public void TypesThatContain()
        {
            var test = (Func <Type, bool>)TypesThat.Contains("That");

            Assert.True(test(typeof(TypesThatTests)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#15
0
        public void TypesThatAreInTheSameNamespace()
        {
            var test = (Func <Type, bool>)TypesThat.AreInTheSameNamespace("EasyRpc.Tests.Middleware");

            Assert.True(test(typeof(TypesThatTests)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#16
0
        public void TypesThat_ArePublic()
        {
            var testFunc = (Func <Type, bool>)TypesThat.ArePublic();

            Assert.True(testFunc(typeof(DependentService <>)));
            Assert.False(testFunc(typeof(PrivateClass)));
        }
示例#17
0
        public void TypesThatEndWith()
        {
            var test = (Func <Type, bool>)TypesThat.EndWith("Tests");

            Assert.True(test(typeof(TypesThatTests)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#18
0
        public void TypesThatHaveAttributeGeneric()
        {
            var test = (Func <Type, bool>)TypesThat.HaveAttribute <SomeAttribute>();

            Assert.True(test(typeof(AttributedClass)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#19
0
        public void TypesThatAreOpenGeneric()
        {
            var test = (Func <Type, bool>)TypesThat.AreOpenGeneric();

            Assert.True(test(typeof(OpenGeneric <>)));
            Assert.False(test(typeof(OpenGeneric <int>)));
        }
示例#20
0
        public void HaveAttributeGeneric()
        {
            Func <Type, bool> haveFilter = TypesThat.HaveAttribute(typeof(SomeTestAttribute));

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectE)));
        }
示例#21
0
        public void AreInTheSameNamespaceAndSubnamespaceGeneric()
        {
            Func <Type, bool> sameNamespace = TypesThat.AreInTheSameNamespaceAs <DependencyInjectionContainer>(true);

            Assert.True(sameNamespace(typeof(TypesThat)));

            Assert.False(sameNamespace(GetType()));
        }
示例#22
0
        public void TypesThat_StartWith_Not()
        {
            Func <Type, bool> haveFilter = TypesThat.Not().StartWith("A");

            Assert.False(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.True(haveFilter(typeof(BasicService)));
        }
示例#23
0
        public void TypesThat_Contains()
        {
            Func <Type, bool> haveFilter = TypesThat.Contains("Simple");

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(BasicService)));
        }
示例#24
0
        public void TypesThat_And()
        {
            Func <Type, bool> haveFilter = TypesThat.StartWith("Attributed").And.EndWith("B");

            Assert.False(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.True(haveFilter(typeof(AttributedSimpleObjectB)));
        }
示例#25
0
        public void TypesThatHavePropertyGenericTyped()
        {
            var test = (Func <Type, bool>)TypesThat.HaveProperty <int>();

            Assert.True(test(typeof(PropertyClass)));
            Assert.True(test(typeof(OtherPropertyClass)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#26
0
        public void TypesThatHavePropertyTypedFiltered()
        {
            var test = (Func <Type, bool>)TypesThat.HaveProperty(typeof(int), "IntValue");

            Assert.True(test(typeof(PropertyClass)));
            Assert.False(test(typeof(OtherPropertyClass)));
            Assert.False(test(typeof(IntMathService)));
        }
示例#27
0
        public void OrFilteredTest()
        {
            Func <Type, bool> haveFilter = TypesThat.EndWith("A").Or.EndWith("B");

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.True(haveFilter(typeof(AttributedSimpleObjectB)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectC)));
        }
示例#28
0
        public void HaveAttributeGenericFiltered()
        {
            Func <Type, bool> haveFilter = TypesThat.HaveAttribute <SomeTestAttribute>(x => x.TestValue == 5);

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectB)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectE)));
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseJsonRpc("/", api =>
                           api.ExposeAssemblyContaining <Startup>()
                           .Where(TypesThat.AreInTheSameNamespaceAs <CalculatorService>()));
        }
示例#30
0
        public void HaveAttributeTypeFiltered()
        {
            Func <Type, bool> haveFilter = TypesThat.HaveAttribute(typeof(SomeTestAttribute),
                                                                   x => ((SomeTestAttribute)x).TestValue == 5);

            Assert.True(haveFilter(typeof(AttributedSimpleObjectA)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectB)));

            Assert.False(haveFilter(typeof(AttributedSimpleObjectE)));
        }