Get started with the RavenDB integrations
Ce contenu n’est pas encore disponible dans votre langue.
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.
Set up hosting integration
Section titled “Set up hosting integration”To begin, install the Aspire RavenDB Hosting integration in your Aspire AppHost project:
aspire add communitytoolkit-ravendbLa CLI Aspire est interactive ; choisissez le résultat approprié lorsque demandé :
Select an integration to add:
> communitytoolkit-ravendb (CommunityToolkit.Aspire.Hosting.RavenDB)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.RavenDB@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.RavenDB" Version="*" />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:
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...Set up client integration
Section titled “Set up client integration”In each of the consuming client projects, install the Aspire RavenDB client integration:
dotnet add package CommunityToolkit.Aspire.RavenDB.Client#:package CommunityToolkit.Aspire.RavenDB.Client@*<PackageReference Include="CommunityToolkit.Aspire.RavenDB.Client" Version="*" />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.