Skip to content

Commit

Permalink
New ICodeFileCollectionWithServices marker interface that Wolverine w…
Browse files Browse the repository at this point in the history
…ill need. Making code file collections opt in to using the IoC code generation. Bumps to 3.5.0
  • Loading branch information
jeremydmiller committed Feb 19, 2024
1 parent 949eb63 commit 6f0fb3e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<VersionPrefix>3.4.1</VersionPrefix>
<VersionPrefix>3.5.0</VersionPrefix>
<LangVersion>10.0</LangVersion>
<Authors>Jeremy D. Miller;Babu Annamalai;Oskar Dudycz;Joona-Pekka Kokko</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
Expand Down
4 changes: 4 additions & 0 deletions src/GeneratorTarget/GreeterGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public IReadOnlyList<ICodeFile> BuildFiles()
};
}

public bool ShouldUseContainerServices { get; } = false;

public string ChildNamespace { get; } = "Helpers.Greeters";

public GenerationRules Rules { get; } = new GenerationRules
Expand All @@ -91,6 +93,8 @@ public IReadOnlyList<ICodeFile> BuildFiles()
};
}

public bool ShouldUseContainerServices { get; } = false;

public string ChildNamespace { get; } = "Helpers.Greeters2";

public GenerationRules Rules { get; } = new GenerationRules
Expand Down
6 changes: 4 additions & 2 deletions src/JasperFx.CodeGeneration/DynamicCodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public string GenerateCodeFor(string childNamespace)

public void WriteGeneratedCode(Action<string> onFileWritten)
{

foreach (var collection in Collections)
{
var directory = collection.Rules.GeneratedCodeOutputPath.ToFullPath();
Expand Down Expand Up @@ -102,7 +101,10 @@ private string generateCode(ICodeFileCollection collection)
var files = collection.BuildFiles();
foreach (var file in files) file.AssembleTypes(generatedAssembly);

return generatedAssembly.GenerateCode(ServiceVariableSource);
// This was important. Each source code collection should explicitly opt into using IoC services rather
// than making that automatic
var services = collection is ICodeFileCollectionWithServices ? ServiceVariableSource : null;
return generatedAssembly.GenerateCode(services);
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/JasperFx.CodeGeneration/ICodeFileCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

namespace JasperFx.CodeGeneration;

/// <summary>
/// Code file collection that should be generated with IoC sourced
/// dependencies. This was originally built to support Wolverine message handlers
/// </summary>
public interface ICodeFileCollectionWithServices : ICodeFileCollection{}

public interface ICodeFileCollection
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/JasperFx.CodeGeneration/JasperFx.CodeGeneration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FastExpressionCompiler" Version="4.0.0" />
<PackageReference Include="FastExpressionCompiler" Version="4.1.0" />
<PackageReference Include="JasperFx.Core" Version="1.5.0" />
</ItemGroup>
</Project>
Expand Down

0 comments on commit 6f0fb3e

Please sign in to comment.