RavenDB Client integration reference
Ce contenu n’est pas encore disponible dans votre langue.
To get started with the Aspire RavenDB integrations, follow the Get started with RavenDB integrations guide.
This article includes full details about the Aspire RavenDB Client integration.
Installation
Section titled “Installation”To get started with the Aspire RavenDB client integration, install the 📦 CommunityToolkit.Aspire.RavenDB.Client NuGet package in the client-consuming project. The RavenDB client integration registers an IDocumentStore instance, which serves as the entry point for interacting with the RavenDB server. If your AppHost includes RavenDB database resources, the associated IDocumentSession and IAsyncDocumentSession instances are also registered for dependency injection.
dotnet add package CommunityToolkit.Aspire.RavenDB.Client#:package CommunityToolkit.Aspire.RavenDB.Client@*<PackageReference Include="CommunityToolkit.Aspire.RavenDB.Client" Version="*" />Add RavenDB client
Section titled “Add 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:
public class ExampleService(IDocumentStore client){ // Use client...}Add RavenDB client using settings
Section titled “Add RavenDB client using settings”The AddRavenDBClient method provides overloads that accept a RavenDBClientSettings object:
var settings = new RavenDBClientSettings{ Urls = new[] { serverUrl }, DatabaseName = myDatabaseName, Certificate = myCertificate};
builder.AddRavenDBClient(settings: settings);Add keyed RavenDB client
Section titled “Add keyed RavenDB client”If your application requires multiple IDocumentStore instances with different connection configurations, you can register keyed RavenDB clients:
builder.AddKeyedRavenDBClient(serviceKey: "production", connectionName: "production");builder.AddKeyedRavenDBClient(serviceKey: "testing", connectionName: "testing");Then you can retrieve the IDocumentStore instances using dependency injection:
public class ExampleService( [FromKeyedServices("production")] IDocumentStore production, [FromKeyedServices("testing")] IDocumentStore testing){ // Use databases...}Configuration
Section titled “Configuration”The Aspire RavenDB Client integration provides multiple configuration approaches and options to meet the requirements and conventions of your project.
Use a connection string
Section titled “Use a connection string”When using a connection string from the ConnectionStrings configuration section, provide the name of the connection string:
builder.AddRavenDBClient("ravendb");The connection string will be retrieved from the ConnectionStrings configuration section:
{ "ConnectionStrings": { "ravendb": "Url=http://localhost:8080/;Database=ravendb" }}Use configuration providers
Section titled “Use configuration providers”The Aspire RavenDB integration supports configuration. It loads the RavenDBClientSettings from the configuration using the Aspire:RavenDB:Client key:
{ "Aspire": { "RavenDB": { "Client": { "ConnectionString": "URL=http://localhost:8080;Database=ravendb", "DisableHealthChecks": false, "HealthCheckTimeout": 10000, "DisableTracing": false } } }}Use inline configurations
Section titled “Use inline configurations”You can also pass an Action<RavenDBClientSettings> delegate to set up options inline:
builder.AddRavenDBClient(connectionName: "ravendb", configureSettings: settings => { settings.CreateDatabase = true; settings.Certificate = myCertificate; settings.DisableTracing = true; });Client integration health checks
Section titled “Client integration health checks”The Aspire RavenDB client integration uses the configured client to perform a health check. If successful, the health check is considered healthy.