CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.05k stars 172 forks source link

Add support for registering an endpoint filter using an endpoint filter factory #323

Closed ergonzalez-boh closed 1 month ago

ergonzalez-boh commented 12 months ago

Currently, Carter provides the ability to register endpoint filters through the CarterModule Before and After delegates. However, there is no built-in mechanism to incorporate an EndpointFilterFactory that would allow dynamic determination of whether an endpoint filter should be added to a specific endpoint during startup.

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/min-api-filters?view=aspnetcore-7.0#register-a-filter-using-an-endpoint-filter-factory

leandrods commented 3 months ago

Hello @ergonzalez-boh

RouteGroupBuilder root = app.MapGroup("/api");
root.MapCarter();
root.AddEndpointFilterFactory(ValidationFilter.ValidationFilterFactory);

Can't you solve it with that?

jchannon commented 1 month ago

Closing - as of .NET6 you should be using ICarterModule not CarterModule and you can use the EndpointFilterFactory stuff directly