Following is a example of me specifing a Endpoint as i usually do, but i recognized a situation that i cant explain myself.
In the First example i specify the delagete abcDelegate and use it in the .MapGet where i expect to use this Signature: With the Delegate not the RequestDelegate!
public static RouteHandlerBuilder MapGet(
this IEndpointRouteBuilder endpoints,
[StringSyntax("Route")] string pattern,
Delegate handler)
Works but is unecesary long with the delegate not as a lamda
internal sealed class CheckMailStatus : IEndpoint
{
private static async Task abcDelegate(string id, IEmailRepository emailRepository)
{
IEnumerable a = await emailRepository.GetAllAsync();
InternalGenericEmail? result = a.FirstOrDefault(p => p.Id.ToString() == id);
if (result is not null)
{
return TypedResults.Ok(result);
}
return TypedResults.NotFound($"Die angegebne Id: {id} ist nciht vorhanden");
}
public void MapEndpoint(IEndpointRouteBuilder app) => app.MapGet("api/notifier/generic/check/{id}", abcDelegate);
}
When the delegate is declared inline the issue Delegate "RequestDelegate" does not take 2 arguments apear.
internal sealed class CheckMailStatus : IEndpoint
{
public void MapEndpoint(IEndpointRouteBuilder app) => app.MapGet("api/notifier/generic/check/{id}", async (string id, IEmailRepository emailRepository) =>
{
IEnumerable a = await emailRepository.GetAllAsync();
InternalGenericEmail? result = a.FirstOrDefault(p => p.Id.ToString() == id);
if (result is not null)
{
return TypedResults.Ok(result);
}
return TypedResults.NotFound($"Die angegebne Id: {id} ist nciht vorhanden");
}
);
}
I thought that those two exmaple are Equal in function or does the MapGet not support the Delegate as a Lambda?