Skip to main content

Getting a Client

All operations in Clustron DKV are performed through a client.

Before you can use the API, you need to:

  1. Register stores
  2. Resolve a client
  3. Start using it

Registering Stores​

Use dependency injection to register your stores.

using Clustron.DKV.Client.DependencyInjection;

services.AddClustronDkvStores(
configuration.GetSection("Dkv:Stores"));

This reads store configuration from appsettings.json.


Example Configuration​

{
"Dkv": {
"Stores": {
"default": {
"Mode": "Remote",
"Seeds": [
{ "Host": "localhost", "Port": 7861 }
]
}
}
}
}

Resolving a Client​

Use IDkvClientProvider to get a client for a store.

var provider = services.GetRequiredService<IDkvClientProvider>();

var client = await provider.GetAsync("default");

What is IDkvClientProvider?​

IDkvClientProvider:

  • Manages connections to stores
  • Creates and caches client instances
  • Ensures efficient reuse

You should use it instead of creating clients manually.


Multiple Stores​

You can define and use multiple stores:

{
"Dkv": {
"Stores": {
"orders": {
"Mode": "Remote",
"Seeds": [
{ "Host": "orders-node", "Port": 7861 }
]
},
"local": {
"Mode": "InProc"
}
}
}
}

Resolve a specific store:

var ordersClient = await provider.GetAsync("orders");
var localClient = await provider.GetAsync("local");

InProc vs Remote​

The client API is identical for both modes.

InProc​

{
"Mode": "InProc"
}

Remote​

{
"Mode": "Remote",
"Seeds": [
{ "Host": "localhost", "Port": 7861 }
]
}

No code changes are required when switching modes.


Best Practices​

  • Register stores once during application startup
  • Reuse IDkvClientProvider
  • Avoid creating clients manually
  • Use configuration to switch environments

What’s Next​

👉 Continue to Basic Operations to start working with data