Meilisearch integration
Meilisearch is a fast, open-source search engine that makes search and discovery easy. The Aspire Meilisearch integration enables you to connect to existing Meilisearch instances or create new instances from Aspire using the docker.io/getmeili/meilisearch container image.
Hosting integration
Section titled “Hosting integration”To run the Meilisearch container, install the 📦 CommunityToolkit.Aspire.Hosting.Meilisearch NuGet package in the AppHost project.
aspire add communitytoolkit-meilisearchThe Aspire CLI is interactive, be sure to select the appropriate search result when prompted:
Select an integration to add:
> communitytoolkit-meilisearch (CommunityToolkit.Aspire.Hosting.Meilisearch)> Other results listed as selectable options...#:package CommunityToolkit.Aspire.Hosting.Meilisearch@*<PackageReference Include="CommunityToolkit.Aspire.Hosting.Meilisearch" Version="*" />Add Meilisearch resource
Section titled “Add Meilisearch resource”In the AppHost project, register and consume the Meilisearch integration using the AddMeilisearch extension method to add the Meilisearch container to the application builder.
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch");
builder.AddProject<Projects.ExampleProject>() .WithReference(meilisearch);
// After adding all resources, run the app...The Meilisearch resource includes a randomly generated master key when one wasn’t provided.
Add Meilisearch resource with data volume
Section titled “Add Meilisearch resource with data volume”To add a data volume to the Meilisearch resource, call the WithDataVolume method:
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch") .WithDataVolume();
builder.AddProject<Projects.ExampleProject>() .WithReference(meilisearch);
// After adding all resources, run the app...The data volume is used to persist the Meilisearch data outside the lifecycle of its container. The data volume is mounted at the /meili_data path in the Meilisearch container.
Add Meilisearch resource with data bind mount
Section titled “Add Meilisearch resource with data bind mount”To add a data bind mount to the Meilisearch resource, call the WithDataBindMount method:
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch") .WithDataBindMount(source: @"C:\Meilisearch\Data");
builder.AddProject<Projects.ExampleProject>() .WithReference(meilisearch);
// After adding all resources, run the app...Data bind mounts rely on the host machine’s filesystem to persist the Meilisearch data across container restarts.
Add Meilisearch resource with master key parameter
Section titled “Add Meilisearch resource with master key parameter”When you want to explicitly provide the master key used by the container image, you can provide these credentials as parameters:
var builder = DistributedApplication.CreateBuilder(args);
var masterkey = builder.AddParameter("masterkey", secret: true);var meilisearch = builder.AddMeilisearch("meilisearch", masterkey);
builder.AddProject<Projects.ExampleProject>() .WithReference(meilisearch);
// After adding all resources, run the app...Client integration
Section titled “Client integration”To get started with the Aspire Meilisearch client integration, install the 📦 CommunityToolkit.Aspire.Meilisearch NuGet package in the client-consuming project.
dotnet add package CommunityToolkit.Aspire.Meilisearch#:package CommunityToolkit.Aspire.Meilisearch@*<PackageReference Include="CommunityToolkit.Aspire.Meilisearch" Version="*" />Add Meilisearch client
Section titled “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");You can then retrieve the MeilisearchClient instance using dependency injection:
public class ExampleService(MeilisearchClient client){ // Use client...}Add keyed Meilisearch client
Section titled “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
Section titled “Configuration”The Aspire Meilisearch client integration provides multiple options to configure the server connection.
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.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
Section titled “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
Section titled “Client integration health checks”The Aspire Meilisearch integration uses the configured client to perform a health check.