feat: Assembly search nested handler type filtering

Fix the assembly handler scanning and do not allow nested handlers to be present.
This commit is contained in:
Louis Seubert 2026-05-23 16:17:16 +02:00
commit e3d16c9f56
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
7 changed files with 249 additions and 15 deletions

View file

@ -29,7 +29,7 @@ public static Task<int> Main()
{
var collection = new ServiceCollection();
collection.AddRequestDispatcher(builder => builder
.Add(typeof(ScalarHandler))
.SearchHandlerInAssembly(typeof(ScalarHandler).Assembly)
.Add(typeof(ScalarBehavior)));
await using var provider = collection.BuildServiceProvider();
var dispatcher = provider.GetRequiredService<IRequestDispatcher>();
@ -46,17 +46,17 @@ public class ScalarRequest : IScalarRequest<string>
public string Value { get; set; } = string.Empty;
}
public class ScalarHandler : IScalarRequestHandler<ScalarTestRequest, string>
public class ScalarHandler : IScalarRequestHandler<ScalarRequest, string>
{
public Task<string> HandleAsync(ScalarTestRequest request, CancellationToken cancellationToken)
public Task<string> HandleAsync(ScalarRequest request, CancellationToken cancellationToken)
{
return Task.FromResult($"{request.Value} World");
}
}
public class ScalarBehavior : IScalarRequestBehavior<ScalarTestRequest, string>
public class ScalarBehavior : IScalarRequestBehavior<ScalarRequest, string>
{
public async Task<string> HandleAsync(ScalarTestRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
public async Task<string> HandleAsync(ScalarRequest request, ScalarHandlerDelegate<string> next, CancellationToken cancellationToken)
{
Console.WriteLine("Before");
var result = await next(request, cancellationToken);