{"id":22274163,"url":"https://github.com/ethern-myth/c-em-env","last_synced_at":"2025-03-25T16:43:22.472Z","repository":{"id":227329197,"uuid":"771099478","full_name":"Ethern-Myth/c-em-env","owner":"Ethern-Myth","description":"The `c-em-env` package simplifies dynamic variable access in C# applications, particularly for retrieving values from environment variables and configuration settings. It offers convenient functionality to handle `.env` files commonly used for configuration management.","archived":false,"fork":false,"pushed_at":"2024-05-12T14:19:38.000Z","size":233,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-19T20:46:58.227Z","etag":null,"topics":["configuration","csharp","env","environment-variables","interface"],"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/Ethern-Myth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["ethern-myth"]}},"created_at":"2024-03-12T17:27:33.000Z","updated_at":"2024-05-12T14:18:45.000Z","dependencies_parsed_at":"2024-05-12T14:43:36.281Z","dependency_job_id":"fe392272-91d8-436c-851d-0a69bc460922","html_url":"https://github.com/Ethern-Myth/c-em-env","commit_stats":null,"previous_names":["ethern-myth/c-em-env"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethern-Myth%2Fc-em-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethern-Myth%2Fc-em-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethern-Myth%2Fc-em-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ethern-Myth%2Fc-em-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ethern-Myth","download_url":"https://codeload.github.com/Ethern-Myth/c-em-env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245502804,"owners_count":20626044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["configuration","csharp","env","environment-variables","interface"],"created_at":"2024-12-03T13:18:16.878Z","updated_at":"2025-03-25T16:43:22.447Z","avatar_url":"https://github.com/Ethern-Myth.png","language":"C#","funding_links":["https://github.com/sponsors/ethern-myth"],"categories":[],"sub_categories":[],"readme":"# C-EM-ENV\n\nThe `c-em-env` package simplifies dynamic variable access in C# applications, particularly for retrieving values from environment variables and configuration settings. It offers convenient functionality to handle `.env` files commonly used for configuration management.\n\n![NuGet Version](https://img.shields.io/nuget/v/c-em-env)\n\n![GitHub Tag](https://img.shields.io/github/v/tag/ethern-myth/c-em-env)\n\n![NuGet Downloads](https://img.shields.io/nuget/dt/c-em-env)\n\n\n### Explanation\n\n`Variable`, represents a dynamic variable that retrieves values from environment variables and configuration settings. It offers dynamic access to these values through the `AsDynamic()` method and dynamic property access.\n\n#### Installation\n\n1. **Add Package Reference**:\n\n   Ensure you have the required packages installed. Add the following package references to your project:\n\n   ```bash\n   dotnet add package c-em-env\n   ```\n\n2. **Usage**:\n\n   Register the `Variable` class in your application's service collection during startup:\n\n   ```csharp\n   // Use the EnvFileReader to load the .env file at the beginning of the Program.cs or Startup.cs\n   // NOTE: This step is helpful if .env variables are not loaded from the constructor automatically on program startup\n   EnvFileReader.Read();\n   EnvFileReader.Load();\n\n   // Add the Variable class as a singleton service\n   builder.Services.AddSingleton\u003cIVariable, Variable\u003e();\n\n   // Initialize the Variable class with the application's configuration\n   new Variable(builder.Configuration);\n   ```\n\n#### Constructor\n\n```csharp\n/// Initializes a new instance of the \u003csee cref=\"Variable\"/\u003e class.\n/// \u003cparam name=\"config\"\u003eThe configuration.\u003c/param\u003e\npublic Variable(IConfiguration config)\n```\n\n- `config`: An instance of `IConfiguration` representing the application's configuration settings.\n\n#### Methods\n\n1. `AsDynamic()`\n\n```csharp\n/// Converts the variable to a dynamic object allowing dynamic access to environment variables and configuration settings.\n/// \u003creturns\u003eA dynamic object representing the variable.\u003c/returns\u003e\npublic dynamic AsDynamic()\n```\n\n- Returns a dynamic object representing the environment variables and configuration settings.\n\n2. `GetDynamicValue(string key)`\n\n```csharp\n/// Gets the value of a dynamic property identified by the specified key.\n/// \u003cparam name=\"key\"\u003eThe key of the dynamic property.\u003c/param\u003e\n/// \u003creturns\u003eThe value of the dynamic property.\u003c/returns\u003e\npublic string? GetDynamicValue(string key)\n```\n\n- `key`: The key of the dynamic property.\n- Returns the value of the dynamic property identified by the specified key.\n\n#### Properties\n\n- `this[string key]`\n\n```csharp\n/// Gets or sets the value of a dynamic property identified by the specified key.\n/// \u003cparam name=\"key\"\u003eThe key of the dynamic property.\u003c/param\u003e\n/// \u003creturns\u003eThe value of the dynamic property.\u003c/returns\u003e\npublic dynamic this[string key]\n```\n\n- `key`: The key of the dynamic property.\n- Provides access to the value of a dynamic property identified by the specified key.\n\n### Usage\n\n```csharp\n// Example usage of Variable class\nvar variable = new Variable(configuration);\ndynamic dynamicVariable = variable.AsDynamic();\n\n// Accessing dynamic properties\nstring value = dynamicVariable.SomeKey;\n\n// Getting dynamic property value\nstring value = variable.GetDynamicValue(\"SomeKey\");\n```\n\n### Notes\n\n- This class retrieves values from environment variables and configuration settings.\n- It provides dynamic access to these values using C#'s dynamic feature.\n- Error handling is included for cases where keys are null, whitespace, or not found in the configuration settings.\n\n#### Features\n\n- Retrieve values from environment variables and configuration settings dynamically.\n- Supports dynamic property access for easy retrieval of values.\n\n#### Important Note\n\n- **`.env` File Required**: Ensure you have an `.env` file present in your project directory with the necessary environment variables. The `Variable` class retrieves values from environment variables and requires an `.env` file to function correctly.\n\nThis guide assumes you're using .NET Core or .NET 5+ for your project, although this was created on .NET 8. Make sure to replace `builder` with your appropriate service provider registration mechanism if you're using a different framework or dependency injection container.\n\n\n### Author and Creator\n\n[Ethern Myth](http://www.github.com/ethern-myth)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethern-myth%2Fc-em-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethern-myth%2Fc-em-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethern-myth%2Fc-em-env/lists"}