Skip to content

Meilisearch Client integration reference

⭐ Community Toolkit Meilisearch logo

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.

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

.NET CLI — Add CommunityToolkit.Aspire.Meilisearch package
dotnet add package CommunityToolkit.Aspire.Meilisearch

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");

You can then retrieve the MeilisearchClient instance using dependency injection:

public class ExampleService(MeilisearchClient client)
{
// Use 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...
}

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

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!@#$%"
}
}

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!@#$%"
}
}
}
}

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