/// <summary> /// Compiles <paramref name="unit"/> and returns generated assembly. /// </summary> /// <param name="unit">Source code compile unit.</param> /// <returns>Generated assembly.</returns> private Assembly CompileCodeUnit(CodeCompileUnit unit) { IStaticCompiler compiler = compilerFactory.CreateStatic(); string assemblyFilePath = Path.Combine(configuration.TempDirectory(), nameFormatter.FormatAssemblyFileName()); ICompilerResult result = compiler.FromUnit(unit, assemblyFilePath); if (!result.IsSuccess) { // Save source code if compilation was not successfull. CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp"); string sourceCodePath = Path.Combine(configuration.TempDirectory(), nameFormatter.FormatSourceCodeFileName()); using (StreamWriter writer = new StreamWriter(sourceCodePath)) { provider.GenerateCodeFromCompileUnit(unit, writer, new CodeGeneratorOptions()); } Ensure.Exception.UnCompilableSource(sourceCodePath); } // Load compiled assembly. return(ReflectionFactory.FromCurrentAppDomain().LoadAssembly(assemblyFilePath)); }
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 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 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); } }