trico is a simple configuration library for your .net projects
main | |
develop | |
unit tests | |
version | |
downloads | |
license | |
size |
in-memory | ✓ |
file | ✓ |
environment variables | ✓ |
api | ✕ |
database | ✕ |
You start with adding trico
services to the IServiceCollection
serviceCollection.AddConfiguration();
Add required providers to the IServiceCollection
.
Important! Configurations are looked up in providers in the order of registration in service collection.
In-Memory configuration provider is a non-persistent short-term storage. Used to work with configurations that are set and used in runtime. In coupe with other providers can also be used as a default application configuration
To add provider to your application, use:
serviceProvider.AddInMemoryProvider();
Initial set of configurations can be set by passing Dictionary<string, string>
into the method:
Dictionary<string, string> defaultConfigs = GetDefaultConfigs();
serviceProvider.AddInMemoryProvider(defaultConfigs);
File configuration provider is a persistent long-term storage.
To add provider to your application, use:
serviceCollection.AddFileProvider();
Load params:
name | description |
---|---|
config-filepath | path to the file where configurations are stored |
Environment variable configuration provider is a non-persistent long-term storage. Allows to import application configurations from environment variables, but can't update them.
To add provider to your application, use:
serviceCollection.AddEnvironmentVariableProvider();
Load params:
name | description |
---|---|
prefix | variable name prefix. Used to narrow down the scope of imported variables |
Load configurations either asynchronously:
Dictionary<string, string> options = new Dictionary<string, string>() {
{ "config-filepath", "..." },
{ "prefix", "" },
}
await config.LoadAsync(options, default);
var value = config["key"];
refer to the Playground project