liveBook · Manning

Aspire.Hosting.SqlServer

As explained in Building Distributed Applications that Work

A .NET Aspire hosting integration package for provisioning and configuring SQL Server resources.

Aspire.Hosting.SqlServer adds SQL Server resources to an Aspire host. Create a server and database, then reference the database from the API service. The API can use Aspire’s SQL Server client integration or keep its existing connection-string configuration. section 10.3

Listing 10.6 Full Aspire host with a SQL Server integration
var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddSqlServer("sql").WithLifetime(ContainerLifetime.Persistent);
var sqldb = sql.AddDatabase("sqldb");

var apiService = builder.AddProject<Projects.OnlineShop_ApiService>("apiservice")
    .WithHttpHealthCheck("/health")
    .WaitFor(sqldb)
    .WithReference(sqldb);

builder
    .AddProject<Projects.OnlineShop_Web>("webfrontend")
    .WithExternalHttpEndpoints()
    .WithHttpHealthCheck("/health")
    .WithReference(apiService)
    .WaitFor(apiService);

builder.Build().Run();

A complete host example wires a persistent SQL Server resource and database to the API, then connects the web frontend to the API. section 10.3

How Building Distributed Applications that Work covers it

How deep it goes
Shows host resource wiring and two client configuration approaches, without detailing the integration library’s internals.
Examples
Uses an online-shop API with a SQL Server database and a web frontend in the Aspire host.
What it assumes
Assumes an existing Aspire host and an API service with SQL Server connection configuration.
What you can do after
Configure an Aspire host to provision a SQL Server database and make it available to an API service.
How it connects
Connects .NET Aspire hosting, SQL Server, connection strings, and Entity Framework Core database configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Distributed Applications that Work. The section links point to the parts of the book it draws on.