Skip to content

Commit 1611deb

Browse files
Merge pull request #3674 from dotnet/main
✅ Merge `main` into `live`
2 parents b427bb7 + a7616c8 commit 1611deb

File tree

79 files changed

+1955
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1955
-103
lines changed

docs/community-toolkit/hosting-postgresql-extensions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: PostgreSQL hosting extensions
33
description: Learn how to use the .NET Aspire PostgreSQL extensions package which provides extra functionality to the .NET Aspire PostgreSQL hosting package.
4-
ms.date: 03/04/2025
4+
ms.date: 05/28/2025
55
---
66

77
# .NET Aspire Community Toolkit PostgreSQL hosting extensions
@@ -14,6 +14,7 @@ In this article, you learn about the .NET Aspire Community Toolkit PostgreSQL ho
1414

1515
This package provides the following features:
1616

17+
- [Adminer](https://adminer.org/) management UI
1718
- [DbGate](https://dbgate.org/) management UI
1819

1920
## Hosting integration
@@ -46,4 +47,11 @@ var postgresServer = builder.AddPostgreSQL("PostgreSQL")
4647
.WithDbGate();
4748
```
4849

50+
To add the Adminer management UI to your PostgreSQL resource, call the `WithAdminer` method on the `PostgresServerResource` instance.
51+
52+
```csharp
53+
var postgresServer = builder.AddPostgreSQL("PostgreSQL")
54+
.WithAdminer();
55+
```
56+
4957
This will add a new resource to the app host which will be available from the .NET Aspire dashboard.

docs/community-toolkit/hosting-sqlserver-extensions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: SQL Server hosting extensions
33
description: Learn how to use the .NET Aspire SQL Server extensions package which provides extra functionality to the .NET Aspire SQL Server hosting package.
4-
ms.date: 03/04/2025
4+
ms.date: 05/28/2025
55
---
66

77
# .NET Aspire Community Toolkit SQL Server hosting extensions
@@ -14,6 +14,7 @@ In this article, you learn about the .NET Aspire Community Toolkit SQL Server ho
1414

1515
This package provides the following features:
1616

17+
- [Adminer](https://adminer.org/) management UI
1718
- [DbGate](https://dbgate.org/) management UI
1819

1920
## Hosting integration
@@ -46,4 +47,11 @@ var sqlserver = builder.AddSqlServer("sqlserver")
4647
.WithDbGate();
4748
```
4849

50+
To add the Adminer management UI to your SQL Server resource, call the `WithAdminer` method on the `SqlServerResourceBuilder` instance.
51+
52+
```csharp
53+
var sqlserver = builder.AddSqlServer("sqlserver")
54+
.WithAdminer();
55+
```
56+
4957
This will add a new resource to the app host which will be available from the .NET Aspire dashboard.

docs/database/includes/sql-app-host.md

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,7 @@ For more information, see [dotnet add package](/dotnet/core/tools/dotnet-add-pac
2525

2626
In your app host project, call <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddSqlServer*> to add and return a SQL Server resource builder. Chain a call to the returned resource builder to <xref:Aspire.Hosting.SqlServerBuilderExtensions.AddDatabase*>, to add SQL Server database resource.
2727

28-
```csharp
29-
var builder = DistributedApplication.CreateBuilder(args);
30-
31-
var sql = builder.AddSqlServer("sql")
32-
.WithLifetime(ContainerLifetime.Persistent);
33-
34-
var db = sql.AddDatabase("database");
35-
36-
builder.AddProject<Projects.ExampleProject>()
37-
.WithReference(db)
38-
.WaitFor(db);
39-
40-
// After adding all resources, run the app...
41-
```
28+
:::code language="csharp" source="../snippets/sql-server-integration/AspireApp.AppHost/AppHost.cs":::
4229

4330
> [!NOTE]
4431
> The SQL Server container is slow to start, so it's best to use a _persistent_ lifetime to avoid unnecessary restarts. For more information, see [Container resource lifetime](../../fundamentals/orchestrate-resources.md#container-resource-lifetime).
@@ -81,74 +68,17 @@ IF
8168
CREATE DATABASE [<QUOTED_DATABASE_NAME>];
8269
```
8370

84-
<!-- TODO: Use xref here when available
85-
8671
To alter the default script, chain a call to the <xref:Aspire.Hosting.SqlServerBuilderExtensions.WithCreationScript*> method on the database resource builder:
8772

88-
-->
89-
90-
To alter the default script, chain a call to the `WithCreationScript` method on the database resource builder:
91-
92-
```csharp
93-
var builder = DistributedApplication.CreateBuilder(args);
94-
95-
var sql = builder.AddSqlServer("sql")
96-
.WithLifetime(ContainerLifetime.Persistent);
97-
98-
var databaseName = "app_db";
99-
var creationScript = $$"""
100-
IF DB_ID('{{databaseName}}') IS NULL
101-
CREATE DATABASE [{{databaseName}}];
102-
GO
103-
104-
-- Use the database
105-
USE [{{databaseName}}];
106-
GO
107-
108-
-- Create the todos table
109-
CREATE TABLE todos (
110-
id INT PRIMARY KEY AUTO_INCREMENT, -- Unique ID for each todo
111-
title VARCHAR(255) NOT NULL, -- Short description of the task
112-
description TEXT, -- Optional detailed description
113-
is_completed BOOLEAN DEFAULT FALSE, -- Completion status
114-
due_date DATE, -- Optional due date
115-
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
116-
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
117-
);
118-
GO
119-
120-
""";
121-
122-
var db = sql.AddDatabase(databaseName)
123-
.WithCreationScript(creationScript);
124-
125-
builder.AddProject<Projects.ExampleProject>()
126-
.WithReference(db)
127-
.WaitFor(db);
128-
129-
// After adding all resources, run the app...
130-
```
73+
:::code language="csharp" source="../snippets/sql-server-creation-script/AspireApp.AppHost/AppHost.cs":::
13174

13275
The preceding example creates a database named `app_db` with a single `todos` table. The SQL script is executed when the database resource is created. The script is passed as a string to the `WithCreationScript` method, which is then executed in the context of the SQL Server resource.
13376

13477
### Add SQL Server resource with data volume
13578

13679
To add a data volume to the SQL Server resource, call the <xref:Aspire.Hosting.SqlServerBuilderExtensions.WithDataVolume*> method on the SQL Server resource:
13780

138-
```csharp
139-
var builder = DistributedApplication.CreateBuilder(args);
140-
141-
var sql = builder.AddSqlServer("sql")
142-
.WithDataVolume();
143-
144-
var db = sql.AddDatabase("database");
145-
146-
builder.AddProject<Projects.ExampleProject>()
147-
.WithReference(db)
148-
.WaitFor(db);
149-
150-
// After adding all resources, run the app...
151-
```
81+
:::code language="csharp" source="../snippets/sql-server-data-volume/AspireApp.AppHost/AppHost.cs":::
15282

15383
The data volume is used to persist the SQL Server data outside the lifecycle of its container. The data volume is mounted at the `/var/opt/mssql` path in the SQL Server container and when a `name` parameter isn't provided, the name is generated at random. For more information on data volumes and details on why they're preferred over [bind mounts](#add-sql-server-resource-with-data-bind-mount), see [Docker docs: Volumes](https://docs.docker.com/engine/storage/volumes).
15484

@@ -159,20 +89,7 @@ The data volume is used to persist the SQL Server data outside the lifecycle of
15989

16090
To add a data bind mount to the SQL Server resource, call the <xref:Aspire.Hosting.SqlServerBuilderExtensions.WithDataBindMount*> method:
16191

162-
```csharp
163-
var builder = DistributedApplication.CreateBuilder(args);
164-
165-
var sql = builder.AddSqlServer("sql")
166-
.WithDataBindMount(source: @"C:\SqlServer\Data");
167-
168-
var db = sql.AddDatabase("database");
169-
170-
builder.AddProject<Projects.ExampleProject>()
171-
.WithReference(db)
172-
.WaitFor(db);
173-
174-
// After adding all resources, run the app...
175-
```
92+
:::code language="csharp" source="../snippets/sql-server-bind-mount/AspireApp.AppHost/AppHost.cs":::
17693

17794
[!INCLUDE [data-bind-mount-vs-volumes](../../includes/data-bind-mount-vs-volumes.md)]
17895

@@ -182,20 +99,7 @@ Data bind mounts rely on the host machine's filesystem to persist the SQL Server
18299

183100
When you want to explicitly provide the password used by the container image, you can provide these credentials as parameters. Consider the following alternative example:
184101

185-
```csharp
186-
var builder = DistributedApplication.CreateBuilder(args);
187-
188-
var password = builder.AddParameter("password", secret: true);
189-
190-
var sql = builder.AddSqlServer("sql", password);
191-
var db = sql.AddDatabase("database");
192-
193-
builder.AddProject<Projects.ExampleProject>()
194-
.WithReference(db)
195-
.WaitFor(db);
196-
197-
// After adding all resources, run the app...
198-
```
102+
:::code language="csharp" source="../snippets/sql-server-parameters/AspireApp.AppHost/AppHost.cs":::
199103

200104
For more information on providing parameters, see [External parameters](../../fundamentals/external-parameters.md).
201105

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"appHostPath": "../AspireApp.AppHost/AspireApp.AppHost.csproj"
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var builder = DistributedApplication.CreateBuilder(args);
2+
3+
var sql = builder.AddSqlServer("sql")
4+
.WithDataBindMount(source: @"C:\SqlServer\Data");
5+
6+
var db = sql.AddDatabase("database");
7+
8+
builder.AddProject<Projects.AspireApp_ExampleProject>("exampleproject")
9+
.WithReference(db)
10+
.WaitFor(db);
11+
12+
// After adding all resources, run the app...
13+
14+
builder.Build().Run();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Sdk Name="Aspire.AppHost.Sdk" Version="9.3.0" />
4+
5+
<PropertyGroup>
6+
<OutputType>Exe</OutputType>
7+
<TargetFramework>net9.0</TargetFramework>
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
<UserSecretsId>ba7d27f9-faf2-4dc2-9910-fa27dbbfefe4</UserSecretsId>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" />
15+
<PackageReference Include="Aspire.Hosting.SqlServer" Version="9.3.0" />
16+
<ProjectReference Include="../AspireApp.ExampleProject/AspireApp.ExampleProject.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "https://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"https": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "https://localhost:17260;http://localhost:15287",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development",
11+
"DOTNET_ENVIRONMENT": "Development",
12+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21100",
13+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22102"
14+
}
15+
},
16+
"http": {
17+
"commandName": "Project",
18+
"dotnetRunMessages": true,
19+
"launchBrowser": true,
20+
"applicationUrl": "http://localhost:15287",
21+
"environmentVariables": {
22+
"ASPNETCORE_ENVIRONMENT": "Development",
23+
"DOTNET_ENVIRONMENT": "Development",
24+
"ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19061",
25+
"ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20241"
26+
}
27+
}
28+
}
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.Dcp": "Warning"
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)