Indiko.Blocks.Configuration.AppSettings
2.1.2
dotnet add package Indiko.Blocks.Configuration.AppSettings --version 2.1.2
NuGet\Install-Package Indiko.Blocks.Configuration.AppSettings -Version 2.1.2
<PackageReference Include="Indiko.Blocks.Configuration.AppSettings" Version="2.1.2" />
<PackageVersion Include="Indiko.Blocks.Configuration.AppSettings" Version="2.1.2" />
<PackageReference Include="Indiko.Blocks.Configuration.AppSettings" />
paket add Indiko.Blocks.Configuration.AppSettings --version 2.1.2
#r "nuget: Indiko.Blocks.Configuration.AppSettings, 2.1.2"
#:package Indiko.Blocks.Configuration.AppSettings@2.1.2
#addin nuget:?package=Indiko.Blocks.Configuration.AppSettings&version=2.1.2
#tool nuget:?package=Indiko.Blocks.Configuration.AppSettings&version=2.1.2
Indiko.Blocks.Configuration.AppSettings
Configuration block for loading application settings from JSON files (appsettings.json) in the Indiko framework.
Overview
This package provides a configuration block that loads settings from appsettings.json files, supporting environment-specific configurations and the standard ASP.NET Core configuration hierarchy.
Features
- AppSettings Support: Load configuration from appsettings.json
- Environment-Specific: Automatic loading of appsettings.{Environment}.json
- Type-Safe Configuration: Bind to strongly-typed settings classes
- Hot Reload: Watch for configuration file changes
- Early Loading: Loads before other blocks (BlockLoadOrder -1)
- IConfiguration Integration: Seamlessly integrates with ASP.NET Core configuration
Installation
dotnet add package Indiko.Blocks.Configuration.AppSettings
Quick Start
Enable in Your Application
The AppSettings configuration block is typically auto-discovered and loaded. Simply ensure your appsettings.json file exists:
// appsettings.json
{
"Logging": {
"LogLevel": {
"Default": "Information"
}
},
"MySettings": {
"ApiKey": "your-api-key",
"Endpoint": "https://api.example.com"
}
}
Create Environment-Specific Settings
// appsettings.Development.json
{
"MySettings": {
"Endpoint": "https://dev-api.example.com"
}
}
// appsettings.Production.json
{
"MySettings": {
"ApiKey": "prod-api-key",
"Endpoint": "https://api.example.com"
}
}
Usage Examples
Accessing Configuration
using Microsoft.Extensions.Configuration;
public class MyService
{
private readonly IConfiguration _configuration;
public MyService(IConfiguration configuration)
{
_configuration = configuration;
}
public void DoSomething()
{
var apiKey = _configuration["MySettings:ApiKey"];
var endpoint = _configuration["MySettings:Endpoint"];
}
}
Type-Safe Configuration with Options Pattern
// Define settings class
public class MySettings
{
public string ApiKey { get; set; }
public string Endpoint { get; set; }
public int Timeout { get; set; } = 30;
}
// Register in ConfigureServices
services.Configure<MySettings>(configuration.GetSection("MySettings"));
// Inject and use
public class MyService
{
private readonly MySettings _settings;
public MyService(IOptions<MySettings> options)
{
_settings = options.Value;
}
public async Task<string> CallApiAsync()
{
var client = new HttpClient
{
BaseAddress = new Uri(_settings.Endpoint),
Timeout = TimeSpan.FromSeconds(_settings.Timeout)
};
client.DefaultRequestHeaders.Add("X-API-Key", _settings.ApiKey);
return await client.GetStringAsync("/data");
}
}
Explicit Service Registration
using Indiko.Blocks.Configuration.AppSettings.Extensions;
public override void ConfigureServices(IServiceCollection services)
{
// Explicitly use appsettings configuration
services.UseAppsettingsConfiguration();
// Bind configuration sections
services.Configure<DatabaseSettings>(Configuration.GetSection("Database"));
services.Configure<CacheSettings>(Configuration.GetSection("Cache"));
}
Configuration Hierarchy
The standard ASP.NET Core configuration hierarchy applies:
- appsettings.json
- appsettings.{Environment}.json
- User Secrets (Development only)
- Environment Variables
- Command Line Arguments
Later sources override earlier ones.
Key Components
AppSettingsConfigurationBlock
The main configuration block implementation.
[BlockLoadOrder(-1)]
public sealed class AppSettingsConfigurationBlock : BlockBase, IAppSettingsConfigurationBlock
{
public override void ConfigureServices(IServiceCollection services)
{
services.UseAppsettingsConfiguration();
base.ConfigureServices(services);
}
}
AppsettingsConfigurationBuilder
Builder for creating the AppSettings configuration block.
public class AppsettingsConfigurationBuilder : IBlockConfigurationBuilder
{
public IConfigurationBlock Build()
{
return new AppSettingsConfigurationBlock(configuration, logger);
}
}
Advanced Features
Nested Configuration Sections
{
"Database": {
"ConnectionStrings": {
"Default": "Server=localhost;Database=mydb",
"ReadOnly": "Server=replica;Database=mydb"
},
"CommandTimeout": 30,
"MaxRetryCount": 3
}
}
public class DatabaseSettings
{
public Dictionary<string, string> ConnectionStrings { get; set; }
public int CommandTimeout { get; set; }
public int MaxRetryCount { get; set; }
}
services.Configure<DatabaseSettings>(Configuration.GetSection("Database"));
Array Configuration
{
"AllowedHosts": ["example.com", "*.example.com"],
"Endpoints": [
{
"Name": "Primary",
"Url": "https://api1.example.com"
},
{
"Name": "Secondary",
"Url": "https://api2.example.com"
}
]
}
var allowedHosts = Configuration.GetSection("AllowedHosts").Get<string[]>();
public class EndpointSettings
{
public string Name { get; set; }
public string Url { get; set; }
}
var endpoints = Configuration.GetSection("Endpoints").Get<List<EndpointSettings>>();
Configuration Validation
using System.ComponentModel.DataAnnotations;
public class ApiSettings
{
[Required]
[Url]
public string Endpoint { get; set; }
[Required]
[MinLength(10)]
public string ApiKey { get; set; }
[Range(1, 300)]
public int Timeout { get; set; } = 30;
}
// Enable validation
services.AddOptions<ApiSettings>()
.Bind(Configuration.GetSection("Api"))
.ValidateDataAnnotations()
.ValidateOnStart(); // Validate at startup
File Watching and Hot Reload
Configuration files are automatically watched for changes:
// Changes to appsettings.json are automatically picked up
// when using IOptionsSnapshot or IOptionsMonitor
public class MyService
{
private readonly IOptionsMonitor<MySettings> _settings;
public MyService(IOptionsMonitor<MySettings> settings)
{
_settings = settings;
// Subscribe to changes
_settings.OnChange(newSettings =>
{
Console.WriteLine($"Configuration changed: {newSettings.Endpoint}");
});
}
public void DoWork()
{
// Always gets current value
var current = _settings.CurrentValue;
}
}
Target Framework
- .NET 10
Dependencies
Indiko.Blocks.Configuration.AbstractionsIndiko.Blocks.Common.AbstractionsMicrosoft.Extensions.ConfigurationMicrosoft.Extensions.Configuration.Json
License
See LICENSE file in the repository root.
Related Packages
Indiko.Blocks.Configuration.Abstractions- Configuration abstractionsIndiko.Blocks.Configuration.Consul- Consul-based configurationIndiko.Blocks.Common.Management- Block management system
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Indiko.Blocks.Common.Abstractions (>= 2.1.2)
- Indiko.Blocks.Configuration.Abstractions (>= 2.1.2)
- Microsoft.Extensions.Configuration (>= 10.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.1)
- Microsoft.Extensions.Configuration.CommandLine (>= 10.0.1)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 10.0.1)
- Microsoft.Extensions.Configuration.FileExtensions (>= 10.0.1)
- Microsoft.Extensions.Configuration.Json (>= 10.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.2 | 261 | 12/18/2025 |
| 2.1.1 | 664 | 12/2/2025 |
| 2.1.0 | 655 | 12/2/2025 |
| 2.0.0 | 266 | 9/17/2025 |
| 1.7.23 | 178 | 9/8/2025 |
| 1.7.22 | 170 | 9/8/2025 |
| 1.7.21 | 173 | 8/14/2025 |
| 1.7.20 | 178 | 6/23/2025 |
| 1.7.19 | 170 | 6/3/2025 |
| 1.7.18 | 175 | 5/29/2025 |
| 1.7.17 | 192 | 5/26/2025 |
| 1.7.15 | 134 | 4/12/2025 |
| 1.7.14 | 138 | 4/11/2025 |
| 1.7.13 | 144 | 3/29/2025 |
| 1.7.12 | 161 | 3/28/2025 |
| 1.7.11 | 170 | 3/28/2025 |
| 1.7.10 | 169 | 3/28/2025 |
| 1.7.9 | 165 | 3/28/2025 |
| 1.7.8 | 177 | 3/28/2025 |
| 1.7.5 | 193 | 3/17/2025 |
| 1.7.4 | 171 | 3/16/2025 |
| 1.7.3 | 167 | 3/16/2025 |
| 1.7.2 | 172 | 3/16/2025 |
| 1.7.1 | 193 | 3/11/2025 |
| 1.7.0 | 206 | 3/11/2025 |
| 1.6.8 | 191 | 3/11/2025 |
| 1.6.7 | 250 | 3/4/2025 |
| 1.6.6 | 142 | 2/26/2025 |
| 1.6.5 | 146 | 2/20/2025 |
| 1.6.4 | 140 | 2/20/2025 |
| 1.6.3 | 153 | 2/5/2025 |
| 1.6.2 | 125 | 1/24/2025 |
| 1.6.1 | 144 | 1/24/2025 |
| 1.6.0 | 120 | 1/16/2025 |
| 1.5.2 | 126 | 1/16/2025 |
| 1.5.1 | 155 | 11/3/2024 |
| 1.5.0 | 144 | 10/26/2024 |
| 1.3.2 | 143 | 10/24/2024 |
| 1.3.0 | 142 | 10/10/2024 |
| 1.2.5 | 156 | 10/9/2024 |
| 1.2.4 | 170 | 10/8/2024 |
| 1.2.1 | 113 | 10/3/2024 |
| 1.2.0 | 153 | 9/29/2024 |
| 1.1.1 | 129 | 9/23/2024 |
| 1.1.0 | 159 | 9/18/2024 |
| 1.0.33 | 173 | 9/15/2024 |
| 1.0.28 | 146 | 8/28/2024 |
| 1.0.27 | 181 | 8/24/2024 |
| 1.0.26 | 153 | 7/7/2024 |
| 1.0.25 | 151 | 7/6/2024 |
| 1.0.24 | 153 | 6/25/2024 |
| 1.0.23 | 148 | 6/1/2024 |
| 1.0.22 | 178 | 5/14/2024 |
| 1.0.21 | 166 | 5/14/2024 |
| 1.0.20 | 153 | 4/8/2024 |
| 1.0.19 | 148 | 4/3/2024 |
| 1.0.18 | 173 | 3/23/2024 |
| 1.0.17 | 166 | 3/19/2024 |
| 1.0.16 | 180 | 3/19/2024 |
| 1.0.15 | 159 | 3/11/2024 |
| 1.0.14 | 176 | 3/10/2024 |
| 1.0.13 | 160 | 3/6/2024 |
| 1.0.12 | 180 | 3/1/2024 |
| 1.0.11 | 175 | 3/1/2024 |
| 1.0.10 | 157 | 3/1/2024 |
| 1.0.9 | 178 | 3/1/2024 |
| 1.0.8 | 165 | 2/19/2024 |
| 1.0.7 | 152 | 2/17/2024 |
| 1.0.6 | 171 | 2/17/2024 |
| 1.0.5 | 157 | 2/17/2024 |
| 1.0.4 | 179 | 2/7/2024 |
| 1.0.3 | 166 | 2/6/2024 |
| 1.0.1 | 149 | 2/6/2024 |
| 1.0.0 | 200 | 1/9/2024 |
| 1.0.0-preview99 | 157 | 12/22/2023 |
| 1.0.0-preview98 | 145 | 12/21/2023 |
| 1.0.0-preview97 | 134 | 12/21/2023 |
| 1.0.0-preview96 | 122 | 12/20/2023 |
| 1.0.0-preview95 | 156 | 12/20/2023 |
| 1.0.0-preview94 | 139 | 12/18/2023 |
| 1.0.0-preview101 | 152 | 1/5/2024 |