From the course: ASP.NET Core: Middleware

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Implementing an inline method

Implementing an inline method - ASP.NET Core Tutorial

From the course: ASP.NET Core: Middleware

Implementing an inline method

- [Instructor] Let's write a little piece of middleware here, that will write some timing information into our log about how long it took for the actual processing of that WriteAsync("Hello World!"). I can do this with the app.Use command. And, you see, I'm going to have a func, that takes in a request delegate, and another, a second request delegate. The first one is the context, and then the second one is that next delegate that's going to point to the rest of my http pipeline. So will receive context, and kickoff this inline function. So I will create a timer, using System.Diagnostics.Stopwatch, and we'll start a new one. As soon as this is reached. There we go. And now, I'll pass control, now that we've started our stopwatch, I will pass control on to the next element in the pipeline, by calling the next delegate. So, next is an asynchronous func, of type task, so pass control onto the next thing. So, my request will come through, check to see if there's any static files to…

Contents