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.
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.
