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.06k stars 174 forks source link

CarterOptions() before lambda expression on 5.1.0 #253

Closed heitor481 closed 4 years ago

heitor481 commented 4 years ago

Hi all

On previous carter version, we had the possibility to, inside the Configure method of Startup.cs create a lambda expression inside the app.UserCarter() to inject something on the header response of every call to our api.

So basically the call was something like that:

public void Configure(IApplicationBuilder app, IHostingEnvironment env) 
{
   app.UseCarter(new CarterOptions(before: ctx => Inject(ctx)))
}

private Task<bool> Inject(HttpContext ctx) 
{
   ctx.Response.Headers["our-api-header"] = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();
 return Task.FromResult(true);
}

This is something that was possible on old version of carter. But, on the new one, I didn't see any option like that. So, my question is: is that something like that on Carter 5.1.0? Or it was removed?

Thanks in advanced

jchannon commented 4 years ago

This was done on v5.0.0 and was a breaking change https://github.com/CarterCommunity/Carter/pull/149

We recommend that you use middleware to do this:

app.Use(async (context, next) => { // Do work that doesn't write to the Response. await next.Invoke(); // Do logging or other work that doesn't write to the Response. });

On Thu, 2 Jul 2020 at 16:17, Heitor Ribeiro de Souza < notifications@github.com> wrote:

Hi all

On previous carter version, we had the possibility to, inside the Configure method of Startup.cs create a lambda expression inside the app.UserCarter() to inject something on the header response of every call to our api.

So basically the call was something like that:

public void Configure(IApplicationBuilder app, IHostingEnvironment env) { app.UseCarter(new CarterOptions(before: ctx => Inject(ctx))) }

private Task Inject(HttpContext ctx) { ctx.Response.Headers["our-api-header"] = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString(); return Task.FromResult(true); }

This is something that was possible on old version of carter. But, on the new one, I didn't see any option like that. So, my question is: is that something like that on Carter 5.1.0? Or it was removed?

Thanks in advanced

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/253, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJXMKCNG5DUC7VKQMV3RZSQJZANCNFSM4OO7WBNQ .

heitor481 commented 4 years ago

Got it John!

Thanks a lot for the clarification about that issue.

I'm closing this thread.