Registers a MeilisearchClient in the DI container for connecting to a Meilisearch.
- Meilisearch cluster.
Install the Aspire Meilisearch Client library with NuGet:
dotnet add package CommunityToolkit.Aspire.Meilisearch
In the Program.cs file of your 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("meilisearch");The Aspire Meilisearch Client integration provides multiple options to configure the server connection based on the requirements and conventions of your project.
When using a connection string from the ConnectionStrings configuration section, you can provide the name of the connection string when calling builder.AddMeilisearchClient():
builder.AddMeilisearchClient("meilisearch");And 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 Microsoft.Extensions.Configuration. It loads the MeilisearchClientSettings from configuration by using the Aspire:Meilisearch:Client key. Example appsettings.json that configures some of the options:
{
"Aspire": {
"Meilisearch": {
"Client": {
"Endpoint": "http://localhost:19530/",
"MasterKey": "123456!@#$%"
}
}
}
}Also you can pass the Action<MeilisearchClientSettings> configureSettings delegate to set up some or all the options inline, for example to set the API key from code:
builder.AddMeilisearchClient("meilisearch", settings => settings.MasterKey = "123456!@#$%");In your AppHost project, install the CommunityToolkit.Aspire.Hosting.Meilisearch library with NuGet:
dotnet add package CommunityToolkit.Aspire.Hosting.Meilisearch
Then, in the Program.cs file of AppHost, register a Meilisearch cluster and consume the connection using the following methods:
var meilisearch = builder.AddMeilisearch("meilisearch");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(meilisearch);The WithReference method configures a connection in the MyService project named meilisearch. In the Program.cs file of MyService, the Meilisearch connection can be consumed using:
builder.AddMeilisearchClient("meilisearch");Then, in your service, inject MeilisearchClient and use it to interact with the Meilisearch API:
public class MyService(MeilisearchClient meilisearchClient)
{
// ...
}