fix(shared): enable dapper aot for session handlers
PR Checks / test-and-build (pull_request) Successful in 6m30s

This commit is contained in:
2026-05-20 09:01:34 +03:00
parent 39132be4e8
commit 3251846001
4 changed files with 75 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
[module: Dapper.DapperAot]
+2
View File
@@ -5,10 +5,12 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Dapper.AOT</InterceptorsPreviewNamespaces>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.72" />
<PackageReference Include="Dapper.AOT" Version="1.0.48" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
<PackageReference Include="Npgsql" Version="10.0.2" />
</ItemGroup>
+6
View File
@@ -8,6 +8,12 @@
"resolved": "2.1.72",
"contentHash": "ns4mGqQd9a/MhP8m6w556vVlZIa0/MfUu03zrxjZC/jlr1uVCsUac8bkdB+Fs98Llbd56rRSo1eZH5VVmeGZyw=="
},
"Dapper.AOT": {
"type": "Direct",
"requested": "[1.0.48, )",
"resolved": "1.0.48",
"contentHash": "rsLM3yKr4g+YKKox9lhc8D+kz67P7Q9+xdyn1LmCsoYr1kYpJSm+Nt6slo5UrfUrcTiGJ57zUlyO8XUdV7G7iA=="
},
"Microsoft.Extensions.Logging.Abstractions": {
"type": "Direct",
"requested": "[10.0.5, )",
@@ -0,0 +1,66 @@
using System.Xml.Linq;
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
public sealed class SharedDapperAotConfigurationTests
{
[Fact]
public void SharedProject_ShouldEnableDapperAotForSessionInteractionHandlers()
{
var repoRoot = FindRepositoryRoot();
var sharedProjectPath = Path.Combine(repoRoot, "src", "GmRelay.Shared", "GmRelay.Shared.csproj");
var joinHandler = File.ReadAllText(Path.Combine(
repoRoot,
"src",
"GmRelay.Shared",
"Features",
"Sessions",
"CreateSession",
"JoinSessionHandler.cs"));
var leaveHandler = File.ReadAllText(Path.Combine(
repoRoot,
"src",
"GmRelay.Shared",
"Features",
"Sessions",
"CreateSession",
"LeaveSessionHandler.cs"));
Assert.Contains("using Dapper;", joinHandler, StringComparison.Ordinal);
Assert.Contains("using Dapper;", leaveHandler, StringComparison.Ordinal);
var project = XDocument.Load(sharedProjectPath);
var packageReferences = project
.Descendants("PackageReference")
.Select(reference => reference.Attribute("Include")?.Value)
.ToArray();
var interceptorNamespaces = project
.Descendants("InterceptorsPreviewNamespaces")
.Select(element => element.Value)
.ToArray();
var moduleAttributeFiles = Directory
.EnumerateFiles(Path.GetDirectoryName(sharedProjectPath)!, "*.cs", SearchOption.AllDirectories)
.Select(File.ReadAllText)
.ToArray();
Assert.Contains("Dapper.AOT", packageReferences);
Assert.Contains(interceptorNamespaces, value => value.Contains("Dapper.AOT", StringComparison.Ordinal));
Assert.Contains(moduleAttributeFiles, source => source.Contains("[module: Dapper.DapperAot]", StringComparison.Ordinal));
}
private static string FindRepositoryRoot()
{
var directory = new DirectoryInfo(AppContext.BaseDirectory);
while (directory is not null)
{
if (File.Exists(Path.Combine(directory.FullName, "Directory.Build.props")))
{
return directory.FullName;
}
directory = directory.Parent;
}
throw new InvalidOperationException("Could not locate repository root.");
}
}