11 Building a reusable microservice platform

 

This chapter covers

  • Creating microservices more quickly with a reusable platform
  • Components of a reusable platform
  • Handling concerns that cut across several microservices
  • Understanding middleware and the ASP.NET middleware pipelines
  • Packaging reusable code with NuGet
  • Building a reusable platform from several NuGet packages

A microservice system can include many microservices. You’ll create new ones frequently, either because you’re adding capabilities to the system or because you’re replacing existing microservices. You want to be able to create them quickly but include all the code that makes them behave well in production—that is, the infrastructure code you’ve created in the previous couple of chapters. In this chapter, you’ll start to create a platform—consisting of NuGet packages—that enables you to quickly create new, well-behaved microservices.

11.1 Creating a new microservice should be quick and easy

In chapter 1, I listed a number of characteristics of microservices, including this one: a microservice is responsible for a single capability. I explained that this characteristic is a variation of the single responsibility principle. Taking this seriously drives you toward having many microservices. And as the system evolves, you’ll create new microservices fairly often when the system needs new end user functionality and as your understanding of the domain grows over time.

11.2 Handling cross-cutting concerns

11.3 Creating a reusable microservice platform

11.4 Packaging and sharing cross-cutting code with NuGet

11.4.1 Creating a logging package

11.4.2 Creating a package with monitoring endpoints

11.5 The ASP.NET pipeline

11.5.1 What belongs in middleware?

11.6 Writing middleware

11.6.1 Middleware as lambdas

11.6.2 Middleware classes

11.7 Testing middleware and pipelines

Summary