Meilisearch Client integration reference

Meilisearch logo
⭐ Community Toolkit

To get started with the Aspire Meilisearch integrations, follow the Get started with Meilisearch integrations guide.

This article includes full details about the Aspire Meilisearch Client integration.

Installation

To access the client integration APIs, install the 📦 CommunityToolkit.Aspire.Meilisearch NuGet package in the client-consuming project:

Install the NuGet package
dotnet add package CommunityToolkit.Aspire.Meilisearch

Add Meilisearch client

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

builder.AddMeilisearchClient(connectionName: "meilisearch");

Tip

The connectionName parameter must match the name used when adding the Meilisearch resource in the AppHost project.

You can then retrieve the MeilisearchClient instance using dependency injection:

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

Add keyed Meilisearch client

There might be situations where you want to register multiple MeilisearchClient instances with different connection names. To register keyed Meilisearch clients, call the AddKeyedMeilisearchClient method:

builder.AddKeyedMeilisearchClient(name: "products");
builder.AddKeyedMeilisearchClient(name: "orders");

Then you can retrieve the MeilisearchClient instances using dependency injection:

public class ExampleService(
    [FromKeyedServices("products")] MeilisearchClient productsClient,
    [FromKeyedServices("orders")] MeilisearchClient ordersClient)
{
    // Use clients...
}

Configuration

The Aspire Meilisearch client integration provides multiple options to configure the server connection.

Use a connection string

When using a connection string from the ConnectionStrings configuration section, provide the name of the connection string:

builder.AddMeilisearchClient("meilisearch");

Then the connection string will be retrieved from the ConnectionStrings configuration section:

{
  "ConnectionStrings": {
    "meilisearch": "Endpoint=http://localhost:19530/;MasterKey=123456!@#$%"
  }
}

Use configuration providers

The Aspire Meilisearch Client integration supports configuration. It loads the settings from configuration using the Aspire:Meilisearch:Client key:

{
  "Aspire": {
    "Meilisearch": {
      "Client": {
        "Endpoint": "http://localhost:19530/",
        "MasterKey": "123456!@#$%"
      }
    }
  }
}

Client integration health checks

The Aspire Meilisearch integration uses the configured client to perform a health check.