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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom Action on After hook

Jaxelr opened this issue · comments

I currently have a small library i am trying to use for Caching responses, the way the behavior is defined is somewhat similar to the RequiresAuthentication extension method:

        public static void EnableCaching(this CarterModule module)
        {
            module.Before += async (ctx) => await CheckCache(ctx);
            module.After = async (ctx) => await SetCache(ctx);
        }

The problem i'm facing is that the After Delegate has a protected set, which means i cannot set the module.After outside of the CarterModule class. I'm sure there's a reasoning behind this, is there an alternative for me to do this in a more general fashion ?

It may be better purposed as middleware before Carter is even hit, so you will do something along the lines of

var cacheResult = await CheckCache(ctx);

if(cacheResult != null)
{
next(); //next here is the carter middleware
}

await SetCache(ctx);

So doing it at the ASP.NET Core middleware level rather than carter.

Hope this helps a bit