public void TypesThatHaveProperty() { var test = (Func <Type, bool>)TypesThat.HaveProperty("IntValue"); Assert.True(test(typeof(PropertyClass))); Assert.False(test(typeof(IntMathService))); }
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); }
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))); }
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))); }
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>()); }
public void TypesThatHaveAttributeFilter() { var test = (Func <Type, bool>)TypesThat.HaveAttribute(t => t == typeof(SomeAttribute)); Assert.True(test(typeof(AttributedClass))); Assert.False(test(typeof(IntMathService))); }
public void TypesThatAreNotPublic() { var test = (Func <Type, bool>)TypesThat.AreNotPublic(); Assert.False(test(typeof(TypesThatTests))); Assert.True(test(typeof(PrivateClass))); }
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(); }); }
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))); }
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))); }
public void TypesThatAreInTheSameNamespaceAsGeneric() { var test = (Func <Type, bool>)TypesThat.AreInTheSameNamespaceAs <TypesThatTests>(); Assert.True(test(typeof(TypesThatTests))); Assert.False(test(typeof(IntMathService))); }
public void TypesThatAreBasedOnGeneric() { var test = (Func <Type, bool>)TypesThat.AreBasedOn <BaseClass>(); Assert.True(test(typeof(InheritClass))); Assert.False(test(typeof(TypesThatTests))); }
public void TypesThatContain() { var test = (Func <Type, bool>)TypesThat.Contains("That"); Assert.True(test(typeof(TypesThatTests))); Assert.False(test(typeof(IntMathService))); }
public void TypesThatAreInTheSameNamespace() { var test = (Func <Type, bool>)TypesThat.AreInTheSameNamespace("EasyRpc.Tests.Middleware"); Assert.True(test(typeof(TypesThatTests))); Assert.False(test(typeof(IntMathService))); }
public void TypesThat_ArePublic() { var testFunc = (Func <Type, bool>)TypesThat.ArePublic(); Assert.True(testFunc(typeof(DependentService <>))); Assert.False(testFunc(typeof(PrivateClass))); }
public void TypesThatEndWith() { var test = (Func <Type, bool>)TypesThat.EndWith("Tests"); Assert.True(test(typeof(TypesThatTests))); Assert.False(test(typeof(IntMathService))); }
public void TypesThatHaveAttributeGeneric() { var test = (Func <Type, bool>)TypesThat.HaveAttribute <SomeAttribute>(); Assert.True(test(typeof(AttributedClass))); Assert.False(test(typeof(IntMathService))); }
public void TypesThatAreOpenGeneric() { var test = (Func <Type, bool>)TypesThat.AreOpenGeneric(); Assert.True(test(typeof(OpenGeneric <>))); Assert.False(test(typeof(OpenGeneric <int>))); }
public void HaveAttributeGeneric() { Func <Type, bool> haveFilter = TypesThat.HaveAttribute(typeof(SomeTestAttribute)); Assert.True(haveFilter(typeof(AttributedSimpleObjectA))); Assert.False(haveFilter(typeof(AttributedSimpleObjectE))); }
public void AreInTheSameNamespaceAndSubnamespaceGeneric() { Func <Type, bool> sameNamespace = TypesThat.AreInTheSameNamespaceAs <DependencyInjectionContainer>(true); Assert.True(sameNamespace(typeof(TypesThat))); Assert.False(sameNamespace(GetType())); }
public void TypesThat_StartWith_Not() { Func <Type, bool> haveFilter = TypesThat.Not().StartWith("A"); Assert.False(haveFilter(typeof(AttributedSimpleObjectA))); Assert.True(haveFilter(typeof(BasicService))); }
public void TypesThat_Contains() { Func <Type, bool> haveFilter = TypesThat.Contains("Simple"); Assert.True(haveFilter(typeof(AttributedSimpleObjectA))); Assert.False(haveFilter(typeof(BasicService))); }
public void TypesThat_And() { Func <Type, bool> haveFilter = TypesThat.StartWith("Attributed").And.EndWith("B"); Assert.False(haveFilter(typeof(AttributedSimpleObjectA))); Assert.True(haveFilter(typeof(AttributedSimpleObjectB))); }
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))); }
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))); }
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))); }
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>())); }
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))); }