Chapter 3. Building a Microservice with ASP.NET Core

Up to this point in the book we have only been scratching at the surface of the capabilities of .NET Core. In this chapter we’re going to expand on the simple “hello world” middleware we’ve built and create our first microservice.

We’ll spend a little time defining what a microservice is (and is not), and discuss concepts like API First and Test-Driven Development. Then we’ll build a sample service that manages teams and team membership.

Microservices Defined

Today, as I have been quoted to say, we can’t swing a dead cat without hitting a microservice.1

The word is everywhere, and unfortunately, it is as overloaded and potentially misleading as the acronym SOA was years ago. Every time we see the word, we’re left with questions like, “What is a service, really?” and “Just how micro is micro?” and “Why don’t we just call them ’services'?”

These are all great questions that we should be asking. In many cases, the answer is “It depends.” However, in my years of building modular and highly scalable applications, I’ve come up with a definition of microservice:

A microservice is a standalone unit of deployment that supports a specific business goal. It interacts with backing services, and allows interaction through semantically versioned, well-defined APIs. Its defining characteristic is a strict adherence to the Single Responsibility Principle (SRP).

This might seem like a somewhat controversial ...

Get Building Microservices with ASP.NET Core now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.