Configuration slots for Magic, allowing you to easily read configuration settings in your Magic application. To use package go to https://polterguy.github.io
$ dotnet add package magic.lambda.configThis project provides configuration settings slots for Magic. The project provides the following slots, allowing you to retrieve configuration settings from your "appsettings.json" configuration file, in addition to saving and loading your configuration file.
This slot allows you to retrieve configuration settings. To retrieve settings you can supply a "path" such as "foo:bar" to for instance an invocation to [config.get]. This will traverse into your "foo" config setting, find its "bar" key, and return the value of your "bar" key. Below is an example of usage.
config.get:"foo:bar"
Assuming your configuration file looks like the following.
{
"foo": {
"bar": 42
}
}
... afterwards the value of your [config.get] node will be the following.
config.get:42
Notice - Due to implementation details of .Net and its IConfiguration specifically, values
returned will always be strings, and you'll have to manually convert these to other types, using for
instance the [convert] slot from magic.lambda. This might change in a future release though.
You can also provide a default value that will be returned if no configuration value is found, such
as the following illustrates.
.foo:foo
config.get:"magic:foo:non-existing-key"
get-value:x:@.foo
Since the above "non-existing-key" doesn't exist in your configuration file, the above Hyperlambda will return the value "foo" being the result of the invocation to the [get-value] slot. This allows you to create default values your code resorts to if the specified configuration setting doesn't exist.
Magic is 100% Open Source and you can find the primary project GitHub page here.
The source code for this repository can be found at github.com/polterguy/magic.lambda.config, and you can provide feedback, provide bug reports, etc at the same place.
The projects is copyright Thomas Hansen 2023 - 2024, and professionally maintained by AINIRO.IO.