{"id":19320938,"url":"https://github.com/hamedstack/hamedstack.configuration.database","last_synced_at":"2025-02-24T05:24:10.615Z","repository":{"id":228031547,"uuid":"694751806","full_name":"HamedStack/HamedStack.Configuration.Database","owner":"HamedStack","description":"A library that loads app configurations from relational databases, featuring reload timer and manual reload option, ensuring settings are updated without full redeployment.","archived":false,"fork":false,"pushed_at":"2024-03-18T13:52:20.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-06T05:25:55.373Z","etag":null,"topics":["config","configuration","csharp","csharp-library","dotnet","dotnet-core","load-config","reload","timer","utilities","utlity"],"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/HamedStack.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-21T16:07:55.000Z","updated_at":"2024-03-16T13:29:44.000Z","dependencies_parsed_at":"2024-03-16T14:38:50.350Z","dependency_job_id":"51e5f251-7165-4a2e-bd21-78f8f2b55e9f","html_url":"https://github.com/HamedStack/HamedStack.Configuration.Database","commit_stats":null,"previous_names":["hamedstack/hamedstack.configuration.database"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HamedStack%2FHamedStack.Configuration.Database","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HamedStack%2FHamedStack.Configuration.Database/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HamedStack%2FHamedStack.Configuration.Database/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HamedStack%2FHamedStack.Configuration.Database/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HamedStack","download_url":"https://codeload.github.com/HamedStack/HamedStack.Configuration.Database/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240422302,"owners_count":19798729,"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":["config","configuration","csharp","csharp-library","dotnet","dotnet-core","load-config","reload","timer","utilities","utlity"],"created_at":"2024-11-10T01:34:05.916Z","updated_at":"2025-02-24T05:24:10.587Z","avatar_url":"https://github.com/HamedStack.png","language":"C#","readme":"# Library Overview\n\nThis library enables applications to dynamically load and update configurations from a relational database. It supports automatic refresh intervals and manual reloading of settings, ensuring that your application can adapt to configuration changes on-the-fly without restarting or redeploying the application. \n\n## Features\n\n- **Dynamic Configuration Loading:** Load key/value pairs from a relational database to manage application settings.\n- **Automatic Refresh:** Configure a reload timer to refresh settings automatically at specified intervals.\n- **Manual Reload Option:** Manually trigger a reload of settings to ensure the application can quickly adapt to configuration changes.\n- **Customizable Schema:** Flexibly define the database schema, table, and column names to fit your existing database structure.\n\n## Preparing Your Database\n\nFirst, ensure your database includes a table for storing configuration key/value pairs. The default expected table structure is as follows:\n\n```sql\nCREATE TABLE Settings (\n    Key VARCHAR(255) NOT NULL,\n    Value VARCHAR(255),\n    PRIMARY KEY (Key)\n);\n```\n\n## Library Setup\n\n### Basic Configuration\n\n1. **Establish Database Connection:** Begin by creating a `DbConnection` instance using your database connection string. This connection will be used to load settings from the database.\n\n   ```csharp\n   var connectionString = builder.Configuration.GetConnectionString(\"DefaultConnection\");\n   var dbConnection = new SqlConnection(connectionString);\n   ```\n\n2. **Add Database Configuration to Your Application:** Integrate the database settings into your application's configuration system.\n\n   ```csharp\n   builder.Configuration.AddDatabase(dbConnection);\n   ```\n\n### Advanced Configuration\n\nFor advanced scenarios, you can customize the default behavior by specifying additional options:\n\n```csharp\nbuilder.Configuration.AddDatabase(dbConnection, option =\u003e\n{\n    option.Schema = \"cfg\"; // Default is empty.\n    option.Table = \"Configurations\"; // Default is \"Settings\".\n    option.KeyColumn = \"K\"; // Default is \"Key\".\n    option.ValueColumn = \"V\"; // Default is \"Value\".\n    option.AutoReload = new TimeSpan(0, 0, 0, 20); // Set auto-reload interval for every 20 seconds. Default is no auto reload (zero).\n});\n```\n\n## Using Configuration in Your Application\n\n### Register Configuration Classes\n\n1. **Define Configuration POCO:** Create a class representing your configuration settings, mapping each property to a specific configuration key.\n\n   ```csharp\n   public sealed class Site\n   {\n       public string Name { get; init; } // Maps to Site:Name in the database\n   }\n   ```\n\n2. **Register and Set in DI:** Register your configuration class with the Dependency Injection (DI) container and set it up for use within your application.\n\n   ```csharp\n   builder.Services.Configure\u003cSite\u003e(builder.Configuration.GetSection(\"Site\"));\n   ```\n\n### Accessing Configurations\n\n- Utilize `IOptionsSnapshot` to access the latest configuration values within your application components, ensuring you can react to changes in configuration dynamically.\n\n   ```csharp\n   public class MyController : ControllerBase\n   {\n       private readonly IOptionsSnapshot\u003cSite\u003e _settingsSnapshot;\n\n       public MyController(IOptionsSnapshot\u003cSite\u003e settingsSnapshot)\n       {\n           _settingsSnapshot = settingsSnapshot;\n       }\n   }\n   ```\n\n- Access configuration values through the `_settingsSnapshot` instance. For example, if your database has a record with `Key: Site:Name` and `Value: www.google.com`, you can retrieve this value using `_settingsSnapshot.Value.Name`.\n\n## Refreshing Configuration\n\n- **Automatic Refresh:** If `AutoReload` is set, the library will automatically refresh configuration values from the database at the specified intervals.\n- **Manual Refresh:** Call `DatabaseConfigurationSource.Reload();` to manually trigger a configuration reload at any time.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamedstack%2Fhamedstack.configuration.database","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhamedstack%2Fhamedstack.configuration.database","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhamedstack%2Fhamedstack.configuration.database/lists"}