Skip to content

Commit

Permalink
Merge pull request #174 from dncsvr/issue/internals-visible-to-genera…
Browse files Browse the repository at this point in the history
…ted-assemblies

Issue / Internals Visible to Generated Assemblies
  • Loading branch information
dncsvr authored Sep 23, 2024
2 parents a216096 + 0f4aa90 commit ade7d60
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public static Assembly GetGeneratedAssembly(this ApplicationContext context, str
public static void ConfigureGeneratedAssemblyCollection(this LayerConfigurator configurator, Action<IGeneratedAssemblyCollection> configuration) =>
configurator.Configure(configuration);

/// <summary>
/// Adds a descriptor for a generated assembly with given parameters
///
/// ℹ️ Any layer or feature generates code which accesses non-public members should
/// be explicitly added tobe added to abstraction project `.targets` file
/// </summary>
public static void Add(this IGeneratedAssemblyCollection generatedAssemblies, string name, Action<GeneratedAssemblyDescriptor> descriptorBuilder,
Func<CSharpCompilationOptions, CSharpCompilationOptions>? compilationOptionsBuilder = default
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Assembly Compile()
));

var compilation = CSharpCompilation.Create(
Path.GetRandomFileName(),
$"Baked.g.{_descriptor.Name}",
syntaxTrees: _descriptor.Codes.Select(c => CSharpSyntaxTree.ParseText(c)),
references: _references.Values,
options: _descriptor.CompilationOptions
Expand Down
5 changes: 5 additions & 0 deletions src/recipe/Baked.Recipe.Service/Baked.Recipe.Service.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
<Using Include="System.Threading.Tasks" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Baked.g.AutoMapOrmFeature"/>
<InternalsVisibleTo Include="Baked.g.RestApiLayer"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
<ProjectReference Include="..\..\..\src\recipe\Baked.Recipe.Service\Baked.Recipe.Service.csproj" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Baked.g.AutoMapOrmFeature"/>
<InternalsVisibleTo Include="Baked.g.RestApiLayer"/>
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions test/recipe/Baked.Test.Recipe.Service/Orm/Child.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ protected Child() : this(default!) { }

public virtual Guid Id { get; protected set; } = default!;
public virtual Parent Parent { get; protected set; } = default!;
protected internal virtual Parent? InternalParent { get; protected set; } = default!;

protected internal virtual Child With(Parent parent)
{
Expand Down
10 changes: 10 additions & 0 deletions unreleased.md
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
# Unreleased

## Bugfixes

- Generated `IManyToOneFecher`services was getting compiler error when a
non-public member was accessed, fixed

## Improvements

- Generated assembly names are now set from `Name` property of
`GeneratedAssemblyDescriptor` with `Baked.g.` prefix

0 comments on commit ade7d60

Please sign in to comment.