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

How to configure my filters #321

Closed xts-velkumars closed 1 month ago

xts-velkumars commented 1 year ago

Good day,

How to configure my filters in one place.

I don't want to add AddEndpointFilter in every method.

jchannon commented 1 year ago

In a constructor of your module you can do something like this

this.Before = context =>
{
    var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<DirectorsModule>>();
    logger.LogDebug("Before");
    return null;
};
this.After = context =>
{
    var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<DirectorsModule>>();
    logger.LogDebug("After");
};