{"id":37537605,"url":"https://github.com/drwatson1/configuration-extensions","last_synced_at":"2026-01-16T08:41:21.579Z","repository":{"id":54373454,"uuid":"275401339","full_name":"drwatson1/configuration-extensions","owner":"drwatson1","description":"A couple of utilities to make usage of configuration options a little bit easier in .NetCore 3.1. One of them allows you to expand environment variables in configuration options, the other one can uatomatically bind option class to a section name in `appsettings.json`.","archived":false,"fork":false,"pushed_at":"2021-02-23T12:23:16.000Z","size":55,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-11-27T13:44:35.063Z","etag":null,"topics":["autobind","bind","configuration","environment","environment-variables","netcore31","option","substitute"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drwatson1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-27T15:35:11.000Z","updated_at":"2025-05-14T20:35:03.000Z","dependencies_parsed_at":"2022-08-13T13:41:00.507Z","dependency_job_id":null,"html_url":"https://github.com/drwatson1/configuration-extensions","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/drwatson1/configuration-extensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwatson1%2Fconfiguration-extensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwatson1%2Fconfiguration-extensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwatson1%2Fconfiguration-extensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwatson1%2Fconfiguration-extensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drwatson1","download_url":"https://codeload.github.com/drwatson1/configuration-extensions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drwatson1%2Fconfiguration-extensions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28478048,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T06:30:42.265Z","status":"ssl_error","status_checked_at":"2026-01-16T06:30:16.248Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autobind","bind","configuration","environment","environment-variables","netcore31","option","substitute"],"created_at":"2026-01-16T08:41:20.988Z","updated_at":"2026-01-16T08:41:21.569Z","avatar_url":"https://github.com/drwatson1.png","language":"C#","readme":"# Configuration Extensions\n\nThe project contains two utilities to solve some general problems.\nThese are not a silver bullet and don't solve all your problems, but do your coding a little bit easier.\n\n## AutoBind\n\n[![NuGet](https://img.shields.io/nuget/v/Contrib.Extensions.Configuration.AutoBind.svg)](https://www.nuget.org/packages/Contrib.Extensions.Configuration.AutoBind)\n\nThe package contains helpers to make your code a bit less verbose when you add a new configuration option class to your system. \n\nInstall the package:\n\n```\nInstall-Package Contrib.Extensions.Configuration.AutoBind\n```\n\nUse AutoBind:\n\n```csharp\npublic class MyServerOptions\n{\n    // ...\n}\n\n// in the Startup.cs:\npublic void ConfigureServices(IServiceCollection services)\n{\n    // This call bind the MyServerOptions class to the configuration file section with the 'MyServerOptions' name\n    services.AddOptions\u003cMyServerOptions\u003e().AutoBind();\n}\n```\n\nYou can customize the section name by adding a class-level read-only property or field to the class with the name 'SectionName' as follow:\n\n```csharp\npublic class MyServerOptions\n{\n    // You can use const string field\n    public const string SectionName = \"MyCoolOptions\";\n    // or \n    public static readonly string SectionName = \"AnotherCoolOptions\";\n    // or\n    public static string SectionName { get; }  = \"CoolOptions\";\n}\n```\n\nIf the class contains one of these fields or properties, AutoBind uses it. If not,  it uses the class name.\n\n## VariablesSubstitution\n\n[![NuGet](https://img.shields.io/nuget/v/Contrib.Extensions.Configuration.VariablesSubstitution.svg)](https://www.nuget.org/packages/Contrib.Extensions.Configuration.VariablesSubstitution)\n\nThe package allows you to expand environment variables in configuration files.\n\n### Basic usage\n\nInstall the package:\n\n```\nInstall-Package Contrib.Extensions.Configuration.VariablesSubstitution\n```\n\nDefine a configuration option class:\n\n```csharp\npublic class MyServerOptions\n{\n    public string TempFolder { get; set; }\n    public string DataFiles { get; set; }\n    // other options\n    // ...\n}\n```\n\nBind the class to a configuration file section and configure it:\n\n```csharp\nservices.AddOptions\u003cMyServerOptions\u003e()\n    .AutoBind()\n    .SubstituteVariables(); // This call makes it happen\n```\n\nNow you can add a configuration section and use environment variables in your `appsettings.json`:\n\n```json\n{\n    \"MyServerOptions\": {\n        \"TempFolder\": \"%TEMP%/MyApp\",\n        \"DataFiles\": \"%AppData%/MyApp/DataFiles\"\n    }\n}\n```\n\nThe substitution works for all nested options including any types of mutable lists and dictionaries. So, this will work too:\n\n```csharp\npublic class MyServerOptions\n{\n    public class SubOptions\n    {\n        public string Proxy { get; set; }\n    }\n\n    public string TempFolder { get; set; }\n    public string DataFiles { get; set; }\n    public string[] StringList { get; set; }\n    public SubOptions SubOptions { get; set; }\n    public List\u003cSubOptions\u003e SubOptionsList { get; set; }\n    public Dictionary\u003cstring, string\u003e DictionaryOfStrings { get; set; }\n}\n```\n\n```json\n{\n    \"MyServerOptions\": {\n        \"TempFolder\": \"%TEMP%/MyApp\",\n        \"DataFiles\": \"%AppData%/MyApp/DataFiles\",\n        \"StringList\": [\n            \"value1\",\n            \"%USER%\"\n        ],\n        \"SubOptions\": {\n            \"Proxy\": \"%PROXY_ADDRESS%\"\n        },\n        \"SubOptionsList\": [\n            {\n                \"Proxy\": \"%PROXY_ADDRESS%\",\n            },\n            {\n                \"Proxy\": \"%PROXY_ADDRESS%\",\n            }\n        ],\n        \"DictionaryOfStrings\": {\n            \"s1\": \"%TEMP%/s1\",\n            \"s2\": \"%TEMP%/s2\"\n        }\n    }\n}\n```\n\n### Customization\n\nBut what if you do want to use `$TEMP` or `$(TEMP)` instead of `%TEMP%`, or maybe don't want to use environment variables?\n\nYou can do it with two steps:\n\n1. Implement the interface: \n\n```csharp\nnamespace Contrib.Extensions.Configuration.VariablesSubstitution\n{\n    public interface IVariablesSubstitution\u003cT\u003e\n    {\n        T Substitute(T value);\n    }\n}\n```\n\n2. Register the implementation in the DI-container BEFORE any call of SubstituteVariables:\n\n```csharp\n// Register your implementation\nservices.AddSingleton\u003cIVariablesSubstitution\u003cstring\u003e, YourImplementation\u003e();\n\nservices.AddOptions\u003cMyServerOptions\u003e()\n    .AutoBind()\n    .SubstituteVariables();\n```\n\n## Versions\n\n| Date | Version | Description |\n|-|-|-|\n| 2021-02-22 | 1.2.0 | Support Dictionary\u003cTKey, TValue\u003e of strings and nested options\n| 2020-08-13 | 1.1.0 | Support lists of nested options and strings\n| 2020-07-17 | 1.0.0 | Initial release\n\n\nHave fun!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrwatson1%2Fconfiguration-extensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrwatson1%2Fconfiguration-extensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrwatson1%2Fconfiguration-extensions/lists"}