9 Introducing middleware: writing and testing middleware

 

This chapter covers:

  • Handling concerns that cut across several microservices
  • Understanding middleware, and the ASP.NET Core middleware pipelines
  • Writing middleware
  • Testing middleware and a middleware pipeline

When we’re implementing a system of microservices, some concerns cut across the entire system. These are the things you need every microservice to do, and they’re often related to keeping the system healthy in production:

  • Monitoring
  • Logging errors, requests, performance, and so on
  • Security
  • Policies related to technologies you use in many microservices—for example, handling database connections

All of these lend themselves well to being implemented as middleware. This chapter explores how to use middleware to handle cross-cutting concerns.

9.1 Handling cross-cutting concerns

When you look at a single microservice, we see a number of components. For instance, chapter 2 broke the Shopping Cart microservice down into the components shown in figure 9.1.

Figure 9.1. The view of the Shopping Cart microservice you’ve seen in earlier chapters shows a small number of components that together implement the Shopping microservice behavior.
ch09 fig 01 horsdal2

9.2 The ASP.NET Core pipeline

 
 

9.2.1 What belongs in middleware?

 
 
 
 

9.3 Writing middleware

 
 
 

9.3.1 Middleware as lambdas

 

9.3.2 Middleware classes

 
 
 
 

9.4 Testing middleware and pipelines

 

9.5 Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest