Skip to content
DocsTry Aspire
DocsTry

Set up SQLite in the AppHost

⭐ Community Toolkit SQLite logo

This article is the reference for the Aspire SQLite Hosting integration. It enumerates the AppHost APIs that you use to model a SQLite database resource in your AppHost project.

If you’re new to the SQLite integration, start with the Get started with SQLite integrations guide. For how consuming apps read the connection information this page exposes, see Connect to SQLite.

To start building an Aspire app that uses SQLite, install the 📦 CommunityToolkit.Aspire.Hosting.Sqlite NuGet package in your AppHost project:

Terminal
aspire add sqlite

Learn more about aspire add in the command reference.

This updates your aspire.config.json with the SQLite hosting integration package:

aspire.config.json
{
"packages": {
"CommunityToolkit.Aspire.Hosting.Sqlite": "*"
}
}

Once you’ve installed the hosting integration in your AppHost project, you can add a SQLite resource:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
const
const sqlite: SqliteResource
sqlite
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addSqlite(name: string, options?: {
databasePath?: string;
databaseFileName?: string;
}): SqliteResource (+1 overload)

Adds an Sqlite resource to the application builder.

addSqlite
("sqlite");
const
const exampleProject: ProjectResource
exampleProject
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: {
launchProfileOrOptions?: ProjectResourceOptions;
}): ProjectResource (+1 overload)

Adds a .NET project resource

addProject
("apiservice", "../ExampleProject/ExampleProject.csproj");
await
const exampleProject: ProjectResource
exampleProject
.
ProjectResource.withReference(source: EndpointReference | string | uri, options?: {
connectionName?: string;
optional?: boolean;
name?: string;
} | undefined): ProjectResource (+1 overload)

Adds a reference to another resource

withReference
(
const sqlite: SqliteResource
sqlite
);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();
  1. When Aspire adds a SQLite resource, as shown in the preceding example, it creates the database file in the user’s temporary directory. No container is started because SQLite is an embedded, file-based database.

  2. The AppHost reference call configures a connection in the consuming project named after the referenced SQLite resource, such as sqlite in the preceding example.

Add SQLite resource with custom database file path

Section titled “Add SQLite resource with custom database file path”

By default, Aspire creates the SQLite database file in the user’s temporary directory. To specify a custom location, provide the directory path and file name as arguments to AddSqlite:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
const
const sqlite: SqliteResource
sqlite
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addSqlite(name: string, options?: {
databasePath?: string;
databaseFileName?: string;
}): SqliteResource (+1 overload)

Adds an Sqlite resource to the application builder.

addSqlite
("sqlite", {
databasePath?: string | undefined
databasePath
: "C:\\Database\\Location",
databaseFileName?: string | undefined
databaseFileName
: "my-database.db",
});
const
const exampleProject: ProjectResource
exampleProject
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: {
launchProfileOrOptions?: ProjectResourceOptions;
}): ProjectResource (+1 overload)

Adds a .NET project resource

addProject
("apiservice", "../ExampleProject/ExampleProject.csproj");
await
const exampleProject: ProjectResource
exampleProject
.
ProjectResource.withReference(source: EndpointReference | string | uri, options?: {
connectionName?: string;
optional?: boolean;
name?: string;
} | undefined): ProjectResource (+1 overload)

Adds a reference to another resource

withReference
(
const sqlite: SqliteResource
sqlite
);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

The preceding code creates the SQLite database file at C:\Database\Location\my-database.db. The file is created if it doesn’t already exist.

To add a browser-based management UI alongside your SQLite database, use the WithSqliteWeb extension method:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
const
const sqlite: SqliteResource
sqlite
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addSqlite(name: string, options?: {
databasePath?: string;
databaseFileName?: string;
}): SqliteResource (+1 overload)

Adds an Sqlite resource to the application builder.

addSqlite
("sqlite");
await
const sqlite: SqliteResource
sqlite
.
SqliteResource.withSqliteWeb(options?: {
containerName?: string;
}): SqliteResource (+1 overload)
withSqliteWeb
();
const
const exampleProject: ProjectResource
exampleProject
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: {
launchProfileOrOptions?: ProjectResourceOptions;
}): ProjectResource (+1 overload)

Adds a .NET project resource

addProject
("apiservice", "../ExampleProject/ExampleProject.csproj");
await
const exampleProject: ProjectResource
exampleProject
.
ProjectResource.withReference(source: EndpointReference | string | uri, options?: {
connectionName?: string;
optional?: boolean;
name?: string;
} | undefined): ProjectResource (+1 overload)

Adds a reference to another resource

withReference
(
const sqlite: SqliteResource
sqlite
);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

This adds a container based on ghcr.io/coleifer/sqlite-web connected to the same database file. Each WithSqliteWeb call creates one container per database. When you run the solution, the Aspire dashboard displays the SQLiteWeb resource with an endpoint — select it to open the SQLiteWeb UI in a new browser tab.

For the full reference of SQLite connection properties — and how consuming apps in C#, TypeScript, Python, and Go read them — see Connect to SQLite.

The SQLite hosting integration does not register a health check because SQLite is an embedded, file-based database with no server process to poll. Health checks are available in the C# client integration.