liveBook · Manning

Chapter 2: Managing infrastructure components with containers and integrations

What you will learn in chapter 2 of Building Distributed Applications that Work

Introduces two ways to connect infrastructure components to Aspire applications and explains why service discovery matters when those components and services connect.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces two ways to connect infrastructure components to Aspire applications and explains why service discovery matters when those components and services connect.

Key terms: infrastructure components, Docker containers, Aspire integration libraries, service discovery, configuration, references

2.1 Docker containers

This section explains what Docker containers and images are, why containers are portable and lightweight, and how images can be obtained and reused.

Key terms: Docker container, dependencies, portability, isolation, host OS kernel, virtual machines, Docker image, instantiate, Docker Hub, base images

2.2 Keycloak overview

Introduces Keycloak as an identity provider and explains its security features and portable realm configuration.

Key terms: Keycloak, identity provider (IdP), authentication, authorization, single sign-on (SSO), multifactor authentication, plugins, customizable login pages, realms, JSON file

2.3 Initial setup

The section identifies the starter application used for the Keycloak example and the Docker prerequisite for running it.

Key terms: Aspire Starter Project, Aspire host application, webfrontend, apiservice, Docker environment, Aspire host, Keycloak container

2.4 Adding a Keycloak container to an Aspire host

This section sets up Keycloak as an Aspire-hosted container, imports its realm configuration, connects it to the frontend and API, and explains why endpoint configuration differs between local development and deployment.

Key terms: KeycloakResource, AddResource(), AddContainer(), WithAnnotation(), client secret, bind mount, ImportRealms(), realm, import.json, /opt/keycloak/data/

2.4.1 Configuring the web frontend app

The section configures the web frontend to use Keycloak for OIDC authentication through a realm-specific authority URL and a service-discovered backchannel client.

Key terms: Keycloak realm, realms/OnlineShop/, well-known endpoints, HttpClient, dependency injection, IHttpClientFactory, Backchannel, Authority, Microsoft.AspNetCore.Authentication.OpenIdConnect, front-channel

2.4.2 Configuring API service

This subsection configures the API service to use Keycloak authentication, then checks the Keycloak container and frontend sign-in flow through the Aspire dashboard.

Key terms: OnlineShop.ApiService, AuthExtensions.cs, Bearer token authentication, OIDC, HttpClient, backchannel, idp resource, Container, quay.io/keycloak/keycloak, Aspire dashboard

2.4.3 Other service types Aspire can host

This subsection identifies two less common ways to register services in an Aspire host besides hosting internal Docker containers.

Key terms: external container reference, executable, Aspire host

2.5 How Aspire integration libraries differ from containers

The section distinguishes Aspire integrations from direct container orchestration and uses Redis output caching to illustrate why a separately hosted integration can help a distributed app.

Key terms: Aspire integrations, Aspire components, extension methods, Docker containers, managed SQL Server instance, stateless, Redis, output caching, distributed cache, application’s memory

2.6 Configuring Aspire integrations on the host

This section explains the two-package structure of a typical Aspire integration and shows how to host Redis and reference it from an app.

Key terms: Aspire integration, NuGet packages, client package, Aspire.Hosting.Redis, OnlineShop.AppHost, AppHost.cs, webfrontend, WithReference()

2.6.1 Connecting to an integration from a hosted service

This subsection shows how a hosted web app connects to a Redis integration and uses it for output caching.

Key terms: Aspire.StackExchange.Redis.OutputCaching, OnlineShop.Web.csproj, service discovery, Redis output caching, local in-memory cache

2.6.2 Viewing integrations in the dashboard

Shows how a locally hosted cache integration appears in the Aspire dashboard and how to identify its container source.

Key terms: cache service, Container, Aspire integration, Source tab, docker.io

2.7 Building an Aspire integration library

This section explains why a local SMTP test server is useful for Keycloak registration emails and starts a class library for a custom MailDev Aspire component.

Key terms: registration, confirmation link, Keycloak, SMTP server, MailDev Docker image, local environment, OnlineShop solution, OnlineShop.MailDev.Hosting, class library, custom Aspire component

2.7.1 Building an integration component

This subsection builds a MailDev Aspire integration component by defining its container resource, pinning its image version, and exposing an extension method for hosting it.

Key terms: MailDevResource, ContainerResource, IResourceWithConnectionString, connection string, SMTP endpoint, MailDevContainerImageTags, registry, Docker image, version tag, MailDevResourceBuilderExtensions

2.7.2 Launching a custom integration from the Aspire host

This section shows how to reference a custom MailDev integration from the Aspire host, launch it, and confirm it is running.

Key terms: OnlineShop.AppHost, IsAspireProjectResource, class library, Aspire service, AppHost.cs, builder, MailDev container, Aspire dashboard, local email inbox

2.8 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 1: Getting started with distributed systems and Aspire Chapter 3: Using database and storage components →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.