Book Image

Practical Microservices with Dapr and .NET - Second Edition

By : Davide Bedin
Book Image

Practical Microservices with Dapr and .NET - Second Edition

By: Davide Bedin

Overview of this book

This second edition will help you get to grips with microservice architectures and how to manage application complexities with Dapr in no time. You'll understand how Dapr simplifies development while allowing you to work with multiple languages and platforms. Following a C# sample, you'll understand how Dapr's runtime, building blocks, and software development kits (SDKs) help you to simplify the creation of resilient and portable microservices. Dapr provides an event-driven runtime that supports the essential features you need for building microservices, including service invocation, state management, and publish/subscribe messaging. You'll explore all of those in addition to various other advanced features with this practical guide to learning Dapr. With a focus on deploying the Dapr sample application to an Azure Kubernetes Service cluster and to the Azure Container Apps serverless platform, you’ll see how to expose the Dapr application with NGINX, YARP, and Azure API Management. By the end of this book, you'll be able to write microservices easily by implementing industry best practices to solve problems related to distributed systems.
Table of Contents (20 chapters)
1
Part 1: Introduction to Dapr
5
Part 2: Building Microservices with Dapr
11
Part 3: Deploying and Scaling Dapr Solutions

Service invocation with the .NET SDK

The best approach to understanding how the Dapr .NET SDK supports service-to-service invocation is to thoroughly examine a sample project.

These are the steps that we will follow:

  1. Create a project for the Order service.
  2. Configure Dapr in ASP.NET.
  3. Implement Dapr with an ASP.NET controller.
  4. Create a project for the Reservation service.
  5. Prepare debugging configuration.
  6. Implement Dapr with an ASP.NET Minimal API.

We will start by creating a project for the first Dapr application in our solution.

Creating a project for the Order service

When creating a project for a Dapr service, we start from the webapi template:

PS C:\Repos\practical-dapr> cd .\chapter04\
PS C:\Repos\practical-dapr\chapter04> dotnet new webapi -o
sample.microservice.order
The template “ASP.NET Core Web API” was created successfully.
Processing post-creation actions...
Running ‘dotnet restore’ on sample...