Zum Inhalt springen

Get started with the RavenDB integrations

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

⭐ Community Toolkit RavenDB logo

RavenDB is a high-performance, open-source NoSQL database designed for fast, efficient, and scalable data storage. It supports advanced features like ACID transactions, distributed data replication, and time-series data management, making it an excellent choice for modern application development. The Aspire RavenDB integration enables you to connect to existing RavenDB instances or create new instances from Aspire using the docker.io/ravendb/ravendb container image.

In this introduction, you’ll see how to install and use the Aspire RavenDB integrations in a simple configuration. If you already have this knowledge, see RavenDB hosting integration for full reference details.

To begin, install the Aspire RavenDB Hosting integration in your Aspire AppHost project:

Aspire CLI — CommunityToolkit.Aspire.Hosting.RavenDB Paket hinzufügen
aspire add communitytoolkit-ravendb

Die Aspire CLI ist interaktiv; das passende Suchergebnis wählen, wenn gefragt:

Aspire CLI — Beispielausgabe
Select an integration to add:
> communitytoolkit-ravendb (CommunityToolkit.Aspire.Hosting.RavenDB)
> Other results listed as selectable options...

Next, in the AppHost project, call the AddRavenDB extension method to add a RavenDB server resource, then call AddDatabase on the server resource to add a database:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var ravenServer = builder.AddRavenDB("ravenServer");
var ravendb = ravenServer.AddDatabase("ravendb");
builder.AddProject<Projects.ExampleProject>()
.WithReference(ravendb)
.WaitFor(ravendb);
// After adding all resources, build and run the app...

In each of the consuming client projects, install the Aspire RavenDB client integration:

.NET CLI — Add CommunityToolkit.Aspire.RavenDB.Client package
dotnet add package CommunityToolkit.Aspire.RavenDB.Client

In the Program.cs file of your client-consuming project, call the AddRavenDBClient extension method to register an IDocumentStore for use via the dependency injection container. The method takes a connection name parameter.

builder.AddRavenDBClient(connectionName: "ravendb");

You can then retrieve the IDocumentStore instance using dependency injection. For example, to retrieve the client from a service:

public class ExampleService(IDocumentStore client)
{
// Use client...
}

For full reference details, see RavenDB hosting integration and RavenDB client integration.