Permalink
Browse files

fixed timing issues in the SM service compilation

  • Loading branch information...
1 parent 47eb36c commit 1049d7755a86f6ed7c9aae6666ba0b67191267f5 @jeremydmiller jeremydmiller committed Dec 22, 2016
@@ -13,7 +13,7 @@ namespace Jasper.Testing.Codegen
{
public class CompilationContext
{
- private readonly GenerationConfig Config = new GenerationConfig("JasperCompilationTesting");
+ protected readonly GenerationConfig Config = new GenerationConfig("JasperCompilationTesting");
private static int _number = 0;
public readonly HandlerChain theChain;
@@ -1,4 +1,5 @@
-using Jasper.Codegen;
+using System;
+using Jasper.Codegen;
using Shouldly;
using Xunit;
@@ -39,5 +40,26 @@ public void use_async_task_if_one_async_that_is_not_last()
theAsyncMode.ShouldBe(AsyncMode.ReturnFromLastNode);
}
+
+ [Fact]
+ public void find_variable_caches_the_values()
+ {
+ throw new NotImplementedException("Do.");
+ }
+
+ [Fact]
+ public void can_find_variables_built_by_one_of_the_existing_frames()
+ {
+ throw new NotImplementedException();
+ }
+
+ [Fact]
+ public void can_find_input_variable()
+ {
+ var generation = new HandlerGeneration(theChain, Config, "input");
+
+ generation.FindVariable(typeof(MainInput))
+ .ShouldBeSameAs(generation);
+ }
}
}
@@ -27,17 +27,11 @@ public void GenerateCode(HandlerGeneration generation, ISourceWriter writer)
internal abstract void generateCode(HandlerGeneration generation, ISourceWriter writer);
- // Going to say that other policies will deal w/ the existence of wrappers
- // Go find necessary variables, add any necessary wrappers
public virtual void ResolveVariables(HandlerGeneration chain)
{
// nothing
}
- // Needs to expose all variables used by this frame,
- // including dependents
- // Use a visitor to find that?
-
public virtual bool CanReturnTask() => false;
public Variable[] Instantiates { get; set; } = new Variable[0];
@@ -49,10 +49,7 @@ public Variable FindVariable(Type type)
private Variable findVariable(Type type)
{
if (type == VariableType) return this;
- foreach (var configSource in _config.Sources)
- {
- Console.WriteLine(configSource);
- }
+
var source = _config.Sources.FirstOrDefault(x => x.Matches(type));
if (source == null)
{
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using Jasper.Codegen.Compilation;
+using StructureMap;
+
+namespace Jasper.Codegen.StructureMap
+{
+ public class NestedContainerVariable : Variable
+ {
+ public NestedContainerVariable() : base(typeof(IContainer), "nested", VariableCreation.BuiltByFrame)
+ {
+ }
+
+ public override IEnumerable<Variable> Dependencies
+ {
+ get { yield return StructureMapServices.Root; }
+ }
+
+ protected override void generateCreation(ISourceWriter writer, Action<ISourceWriter> continuation)
+ {
+ writer.UsingBlock("var nested = _root.GetNestedContainer()", continuation);
+ }
+ }
+}
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using Jasper.Codegen.Compilation;
+
+namespace Jasper.Codegen.StructureMap
+{
+ public class ServiceVariable : Variable
+ {
+ private readonly NestedContainerVariable _parent;
+
+ public ServiceVariable(Type argType, NestedContainerVariable parent) : base(argType, VariableCreation.BuiltByFrame)
+ {
+ _parent = parent;
+ }
+
+ public override IEnumerable<Variable> Dependencies
+ {
+ get
+ {
+ yield return _parent;
+ }
+ }
+
+
+ protected override void generateCreation(ISourceWriter writer, Action<ISourceWriter> continuation)
+ {
+ writer.Write($"var {Name} = {StructureMapServices.Nested.Name}.GetInstance<{VariableType.FullName}>();");
+ continuation(writer);
+ }
+ }
+}
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Generic;
using Baseline;
-using Jasper.Codegen.Compilation;
using StructureMap;
using StructureMap.Pipeline;
@@ -49,51 +47,4 @@ public Variable Create(Type type)
return null;
}
}
-
- public class ServiceVariable : Variable
- {
- private readonly NestedContainerVariable _parent;
-
- public ServiceVariable(Type argType, NestedContainerVariable parent) : base(argType, VariableCreation.BuiltByFrame)
- {
- _parent = parent;
- }
-
- public override IEnumerable<Variable> Dependencies
- {
- get
- {
- yield return _parent;
- }
- }
-
-
- protected override void generateCreation(ISourceWriter writer, Action<ISourceWriter> continuation)
- {
- writer.Write($"var {Name} = {StructureMapServices.Nested.Name}.GetInstance<{VariableType.FullName}>();");
- continuation(writer);
- }
- }
-
-
-
-
- public class NestedContainerVariable : Variable
- {
- public NestedContainerVariable() : base(typeof(IContainer), "nested", VariableCreation.BuiltByFrame)
- {
- }
-
- public override IEnumerable<Variable> Dependencies
- {
- get { yield return StructureMapServices.Root; }
- }
-
- protected override void generateCreation(ISourceWriter writer, Action<ISourceWriter> continuation)
- {
- writer.UsingBlock("var nested = _root.GetNestedContainer()", continuation);
- }
- }
-
-
}

0 comments on commit 1049d77

Please sign in to comment.