Building RESTful Web Services with .NET Core by Gaurav Aroraa Tadit Dash

Building RESTful Web Services with .NET Core by Gaurav Aroraa Tadit Dash

Author:Gaurav Aroraa,Tadit Dash [Gaurav Aroraa]
Language: eng
Format: epub
Tags: COM051310 - COMPUTERS / Programming Languages / C#, COM051470 - COMPUTERS / Programming Languages / ASP .NET, COM060180 - COMPUTERS / Web / Web Services and APIs
Publisher: Packt Publishing
Published: 2018-05-30T10:43:36+00:00


Use

The Use method adds a delegate to the application request pipelines. Look at the following screenshot for the signature of this method:

Signature of Use method

As we discussed in the previous section, the middleware methods can short circuit the request pipeline or pass the request to the next delegate.

Short-circuiting a request is nothing but ending a request.

Look at the following code for the Use method:

public void Configure(IApplicationBuilder app)

{

async Task Middleware(HttpContext context, Func<Task> next)

{

//other stuff

await next.Invoke();

//other stuff

}

app.Use(Middleware);

}

In the preceding code, I have tried to explain the dummy implementation of the Use method with the help of a local function. Here, you can see that Middleware is invoking or passing the request to the next delegate, before or after await next.Invoke();. You can write/implement other code phrases, but these phrases should not send responses to the client, such as those that write output, produce the 404 status, and so on.

Local functions are the methods that are declared within a method and can be called within the scope of the method itself. These methods can only be used by another method.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.