In-Memory Configuration
Configuration of .NET Core applications is typically performed using JSON files, but the Microsoft.Extensions.Configuration system is also able to bind to XML files, environment variables, and in-memory collections.
The following example illustrates how the configuration settings from the sample in the "Configuring Cache Policies" topic could be expressed at runtime using an in-memory dictionary instead of a JSON file.
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Scaleout.Client;
class InMemoryConfig
{
static void Main(string[] args)
{
var conn = GridConnection.Connect("bootstrapGateways=localhost:721");
var configDict = new Dictionary<string, string>
{
// customer and product cache configuration:
{"CacheConfigName", "customers"},
{"ExclusiveLockRetryIntervalMS", "5"},
{"Timeout", "00:45:00"},
{"ClientCacheEviction", "LRU"},
{"ClientCacheCapacity", "1234"},
{"CoherencyInterval", "00:00:00"},
};
var config = new ConfigurationBuilder()
.AddInMemoryCollection(configDict)
.Build();
// Build ScaleOut cache:
var customerCache = new CacheBuilder<string, string>("customers", conn, config)
.Build();
}
}
This approach allows you to express the configuration structure as dictionary keys, separating different levels of the configuration with a colon. See the documentation for the .NET Core Configuration API for more information and examples.