Use community extensions for MySQL hosting
The Aspire Community Toolkit MySQL hosting extensions package provides extra functionality to the Aspire.Hosting.MySql hosting package.
This package provides the following features:
Hosting integration
Section titled “Hosting integration”To get started with the Aspire Community Toolkit MySQL hosting extensions, install the CommunityToolkit.Aspire.Hosting.MySql.Extensions NuGet package in the AppHost project.
aspire add communitytoolkit-mysql-extensionsThe Aspire CLI is interactive, be sure to select the appropriate search result when prompted:
Select an integration to add:
> communitytoolkit-mysql-extensions (CommunityToolkit.Aspire.Hosting.MySql.Extensions)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.MySql.Extensions@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.MySql.Extensions" Version="*" />For TypeScript and Go AppHosts, add the Community Toolkit MySQL extensions package to aspire.config.json:
{ "packages": { "CommunityToolkit.Aspire.Hosting.MySql.Extensions": "*" }}Add management UI
Section titled “Add management UI”DbGate management UI
Section titled “DbGate management UI”To add the DbGate management UI, decorate the official MySqlServerResource builder with WithDbGatewithDbGateWithDbGate:
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const mysql = await builder.addMySql('mysql');await mysql.withDbGate();
const api = await builder.addDotnetProject('api', '../Api/Api.csproj');await api.withReference(mysql);
await builder.build().run();var builder = DistributedApplication.CreateBuilder(args);
var mysql = builder.AddMySql("mysql") .WithDbGate();
builder.AddDotnetProject("api", "../ExampleProject/ExampleProject.csproj") .WithReference(mysql);
builder.Build().Run();builder, err := aspire.CreateBuilder()if err != nil { log.Fatal(aspire.FormatError(err))}
mysql := builder.AddMySql("mysql"). WithDbGate()
builder.AddGoApp("api", "./api"). WithReference(mysql)
app, err := builder.Build()if err != nil { log.Fatal(aspire.FormatError(err))}if err := app.Run(); err != nil { log.Fatal(aspire.FormatError(err))}This adds a new DbGate resource to the AppHost which is available from the Aspire dashboard. DbGate is a comprehensive database management tool that provides a web-based interface for managing your MySQL databases.
Adminer management UI
Section titled “Adminer management UI”To add the Adminer management UI, decorate the official MySqlServerResource builder with WithAdminerwithAdminerWithAdminer:
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const mysql = await builder.addMySql('mysql');await mysql.withAdminer();
const api = await builder.addDotnetProject('api', '../Api/Api.csproj');await api.withReference(mysql);
await builder.build().run();var builder = DistributedApplication.CreateBuilder(args);
var mysql = builder.AddMySql("mysql") .WithAdminer();
builder.AddDotnetProject("api", "../ExampleProject/ExampleProject.csproj") .WithReference(mysql);
builder.Build().Run();builder, err := aspire.CreateBuilder()if err != nil { log.Fatal(aspire.FormatError(err))}
mysql := builder.AddMySql("mysql"). WithAdminer()
builder.AddGoApp("api", "./api"). WithReference(mysql)
app, err := builder.Build()if err != nil { log.Fatal(aspire.FormatError(err))}if err := app.Run(); err != nil { log.Fatal(aspire.FormatError(err))}This adds a new Adminer resource to the AppHost which is available from the Aspire dashboard. Adminer is a lightweight database management tool that provides a simple web interface for database operations.
Using both management UIs
Section titled “Using both management UIs”You can use both management UIs together on the same MySQL resource:
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const mysql = await builder.addMySql('mysql');await mysql.withDbGate();await mysql.withAdminer();
const api = await builder.addDotnetProject('api', '../Api/Api.csproj');await api.withReference(mysql);
await builder.build().run();var builder = DistributedApplication.CreateBuilder(args);
var mysql = builder.AddMySql("mysql") .WithDbGate() .WithAdminer();
builder.AddDotnetProject("api", "../ExampleProject/ExampleProject.csproj") .WithReference(mysql);
builder.Build().Run();builder, err := aspire.CreateBuilder()if err != nil { log.Fatal(aspire.FormatError(err))}
mysql := builder.AddMySql("mysql"). WithDbGate(). WithAdminer()
builder.AddGoApp("api", "./api"). WithReference(mysql)
app, err := builder.Build()if err != nil { log.Fatal(aspire.FormatError(err))}if err := app.Run(); err != nil { log.Fatal(aspire.FormatError(err))}dbx management UI
Section titled “dbx management UI”dbx is a lightweight, web-based database client and an alternative management UI to DbGate and Adminer. Use WithDbxwithDbxWithDbx to add a dbx child resource configured for the MySQL server:
import { createBuilder } from './.aspire/modules/aspire.mjs';
const builder = await createBuilder();
const mysql = await builder.addMySql('mysql');await mysql.withDbx({ containerName: 'mysql-dbx', imageTag: '0.5.33',});
await builder.build().run();var builder = DistributedApplication.CreateBuilder(args);
var mysql = builder.AddMySql("mysql") .WithDbx();
builder.Build().Run();builder, err := aspire.CreateBuilder()if err != nil { log.Fatal(aspire.FormatError(err))}
builder.AddMySql("mysql"). WithDbx(aspire.DbxContainerName("mysql-dbx"), aspire.DbxImageTag("0.5.33"))
app, err := builder.Build()if err != nil { log.Fatal(aspire.FormatError(err))}if err := app.Run(); err != nil { log.Fatal(aspire.FormatError(err))}The C# overload accepts an optional container configuration callback and containerName. The TypeScript and Go bindings accept optional containerName and imageTag values.