Skip to content

armadaplatform/Armada.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hermes (.NET)

Configuration manager for .NET services. This module can be used to find and load configuration files based on MICROSERVICE_ENV (--env) environment variable. Hermes looks for specified config file in entire CONFIG_PATH and loads an appropriate one.

Installation

To install Armada.net and add it to your project simply use Nuget Manager if using Visual Studio and type:

Install-Package Armada.net 

Or add dependency to your project.json if using .NET Core (VSCode or CLI):

  "dependencies": {
    "Armada.net": "1.0.0"
  }

Usage

Import package:

using Armada;

Retrieve configuration specific to current environment (let's assume configuration file is named config.json):

var mainConfig = Hermes.GetConfig("config.json");

For instance config.json could be structured as follows:

{
    "api_secret": "123412341234",
    "db": {
        "url": "192.168.0.1",
        "port": 3306
    }
}

Then in our code we can access these values using following methods:

var apiSecret = mainConfig.GetValue<string>("api_secret");

var dbPort = mainConfig["db"].GetValue<int>("port");

Attempt to access not defined property like:

var dummyEntry = mainConfig.GetValue<string>("dummy_thing");

Will result with ArgumentException being thrown. If you want to retrieve values that might be optional in config file, simply pass default value to GetValue method (this way you may also ommit type specifier as it can be inferred from second argument).

var dummyEntry = mainConfig.GetValue("dummy_thing", "optional_value");

To check if it's safe to access optional configuration section you can use Contains method:

var dummySection = mainConfig["dummy"]; //throws ArgumentException
mainConfig.Contains("dummy"); //returns false
mainConfig.Contains("db"); //returns true
mainConfig.Contains("api_secret"); //returns true

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages