/// <summary> /// Adds <see cref="FilterTypeExecutor"/> to the <paramref name="executorService"/>. /// </summary> /// <param name="executorService">Target service.</param> /// <param name="isExecutedForLatelyLoadedAssemblies">Whether to execute <paramref name="executor"/> also for lately loaded assemblies.</param> /// <returns>Newly created instance of <see cref="FilterTypeExecutor"/>.</returns> public static FilterTypeExecutor AddFiltered(this ITypeExecutorService executorService, bool isExecutedForLatelyLoadedAssemblies) { Ensure.NotNull(executorService, "executorService"); FilterTypeExecutor executor = new FilterTypeExecutor(); executorService.AddTypeExecutor(executor, isExecutedForLatelyLoadedAssemblies); return(executor); }
/// <summary> /// Adds all types found <paramref name="service"/> and marked with <see cref="QueryHandlerAttribute"/> to the <paramref name="dependencyContainer"/>. /// </summary> /// <param name="service">Type enumerating service.</param> /// <param name="dependencyContainer">Container to register handlers to.</param> /// <param name="isExecutedForLatelyLoadedAssemblies">Whether to add query handlers from lately loaded assemblies.</param> /// <returns><paramref name="service"/>.</returns> public static ITypeExecutorService AddQueryHandlers(this ITypeExecutorService service, IDependencyContainer dependencyContainer, bool isExecutedForLatelyLoadedAssemblies = true) { Ensure.NotNull(service, "service"); Ensure.NotNull(dependencyContainer, "dependencyContainer"); service .AddFiltered(isExecutedForLatelyLoadedAssemblies) .AddFilterNotInterface() .AddFilterNotAbstract() .AddFilterHasAttribute <QueryHandlerAttribute>() .AddHandler(t => AddQueryHandler(dependencyContainer, t)); return(service); }
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); }
/// <summary> /// Adds all types found <paramref name="service"/> and marked with <see cref="QueryHandlerAttribute"/> to the <paramref name="collection"/>. /// </summary> /// <param name="service">Type enumerating service.</param> /// <param name="collection">Query handler collection to add handlers to..</param> /// <param name="isExecutedForLatelyLoadedAssemblies">Whether to add query handlers from lately loaded assemblies.</param> /// <returns><paramref name="service"/>.</returns> public static ITypeExecutorService AddQueryHandlers(this ITypeExecutorService service, IQueryHandlerCollection collection, bool isExecutedForLatelyLoadedAssemblies = true) { Ensure.NotNull(service, "service"); Ensure.NotNull(collection, "collection"); service .AddFiltered(isExecutedForLatelyLoadedAssemblies) .AddFilterNotInterface() .AddFilterNotAbstract() .AddFilterHasDefaultConstructor() .AddFilterHasAttribute <QueryHandlerAttribute>() .AddHandler(t => AddQueryHandler(collection, t)); return(service); }
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> >(); }
/// <summary> /// Adds all types found <paramref name="service"/> and marked with <see cref="ConverterAttribute"/> to the <paramref name="repository"/>. /// </summary> /// <param name="service">Type enumerating service.</param> /// <param name="repository">Repository to add converters to.</param> /// <param name="isExecutedForLatelyLoadedAssemblies">Whether to add converters from lately loaded assemblies.</param> /// <returns><paramref name="service"/>.</returns> public static ITypeExecutorService AddConverters(this ITypeExecutorService service, IConverterRepository repository, bool isExecutedForLatelyLoadedAssemblies = true) { Ensure.NotNull(service, "service"); Ensure.NotNull(repository, "repository"); service .AddFiltered(isExecutedForLatelyLoadedAssemblies) .AddFilterNotInterface() .AddFilterNotAbstract() .AddFilterHasDefaultConstructor() .AddFilterHasAttribute <ConverterAttribute>() .AddHandler(t => AddConverter(repository, t)); return(service); }
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()); }
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)); }
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"); }
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) { } }
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); } }
/// <summary> /// Adds all types found <paramref name="service"/> and marked with <see cref="ConverterAttribute"/> to the <see cref="Converts.Repository"/>. /// </summary> /// <param name="service">Type enumerating service.</param> /// <param name="repository">Repository to add converters to.</param> /// <param name="isExecutedForLatelyLoadedAssemblies">Whether to add converters from lately loaded assemblies.</param> /// <returns><paramref name="service"/>.</returns> public static ITypeExecutorService AddConverters(this ITypeExecutorService service, bool isExecutedForLatelyLoadedAssemblies = true) { return(AddConverters(service, Converts.Repository, isExecutedForLatelyLoadedAssemblies)); }