Skip to content

Trico - lightweight end extremely simple configuration tool for .net applications

License

Notifications You must be signed in to change notification settings

Ujinjinjin/trico

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Trico

trico is a simple configuration library for your .net projects

Status

main Build Status
develop Build Status
unit tests Azure DevOps tests
version Nuget
downloads Nuget
license GitHub
size GitHub repo size

Supported providers

in-memory
file
environment variables
api
database

Usage

Step 1. Add Trico services to the service collection

You start with adding trico services to the IServiceCollection

serviceCollection.AddConfiguration();

Step 2. Configure required providers

Add required providers to the IServiceCollection.

Important! Configurations are looked up in providers in the order of registration in service collection.

In-Memory provider

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 provider

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 provider

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

Step 3. Explicitly load configurations

Load configurations either asynchronously:

Dictionary<string, string> options = new Dictionary<string, string>() {
    { "config-filepath", "..." },
    { "prefix", "" },
}
await config.LoadAsync(options, default);

Step 4. Use configurations

var value = config["key"];

More info

refer to the Playground project

About

Trico - lightweight end extremely simple configuration tool for .net applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published