Configuration
Overview
VersaTul.Configurations provides a lightweight, strongly typed way to work with application settings stored in a simple key/value dictionary.
It is especially useful when you want configuration access that is explicit, easy to test, and simple to pass through your application without taking a dependency on the full .NET configuration stack.
Why Use This Package
Use this package when configuration should stay obvious and portable instead of disappearing behind a larger application framework.
It is a strong fit when you want to:
keep settings access testable,
centralize required and optional configuration values in one type, and
reuse the same configuration model across multiple VersaTul packages.
It is less attractive when your team wants every configuration concern to be driven exclusively by the full ASP.NET Core configuration stack and its conventions.
When To Use This Package
Use this package when you want to:
Wrap application settings in strongly typed configuration classes.
Resolve values by property name with minimal boilerplate.
Bind a key/value store into a plain object.
Share one configuration model across multiple VersaTul packages.
Installation
Install the package with the .NET CLI:
dotnet add package VersaTul.Configurations
Or with the Package Manager Console:
PM> NuGet\Install-Package VersaTul.Configurations -Version latest
Start Here If
You want the fastest path from raw settings to a strongly typed configuration class.
You want a simple first VersaTul package that can be evaluated in a console app or service.
You are preparing to add packages such as SQL access, logging, or mail delivery that need explicit settings.
Not The Right First Package If
You are looking for logging, file import, or data access behavior rather than settings access.
You already know you only need built-in framework configuration binding and do not need a reusable VersaTul configuration model.
Works Well With
Configuration Defaults when you want baseline keys and defaults before applying overrides.
Data Sql and Data MsSql when connection metadata needs to stay explicit.
Logger, Logger File, and Mailer when operational packages need shared settings.
Core Types And Concepts
IConfigurationDefines the main configuration API, including
Get<T>(),GetOrDefault<T>(),TryGetValue(), andBind<T>().IAppConfigurationExtends the base configuration abstraction for application-level configuration types.
ConfigurationAbstract base class that implements
IConfiguration. You inherit from this type to create your own strongly typed configuration class.AppConfigurationAbstract application-oriented configuration base type.
ConfigSettingsA dictionary-based settings store used as the source for configuration lookups.
Key Behaviors
Get<T>()uses the calling member name by default, so property-based configuration reads are concise.GetOrDefault<T>()returns the default value forTwhen a key is missing.TryGetValue()lets you inspect presence without throwing.Bind<T>()maps matching keys onto a plain object with writable public properties.The
Configurationbase class supports optional case-insensitive key lookup through its constructor.
Basic Example
The most common usage pattern is to inherit from Configuration and expose strongly typed properties.
using VersaTul.Configurations;
public class StorageConfiguration : Configuration
{
public StorageConfiguration(ConfigSettings settings) : base(settings)
{
}
public string ConnectionString => Get<string>();
public int TimeoutSeconds => GetOrDefault<int>();
public string ArchivePath => Get<string>("ArchiveDirectory");
}
var settings = new ConfigSettings
{
{ "ConnectionString", "Server=.;Database=Demo;Trusted_Connection=True;" },
{ "TimeoutSeconds", 60 },
{ "ArchiveDirectory", "C:\\Exports" }
};
var configuration = new StorageConfiguration(settings);
var connectionString = configuration.ConnectionString;
var timeout = configuration.TimeoutSeconds;
var archivePath = configuration.ArchivePath;
Binding Example
Bind<T>() is useful when you want to project settings into a plain model instead of exposing them through an inherited configuration class.
using VersaTul.Configurations;
public class MailOptions
{
public string SmtpServer { get; set; }
public int SmtpPort { get; set; }
public string FromAddress { get; set; }
}
public class MailConfiguration : Configuration
{
public MailConfiguration(ConfigSettings settings) : base(settings, useCaseInsensitiveKeys: true)
{
}
}
var settings = new ConfigSettings
{
{ "smtpserver", "127.0.0.1" },
{ "smtpport", 25 },
{ "fromaddress", "no-reply@example.com" }
};
var configuration = new MailConfiguration(settings);
var options = configuration.Bind<MailOptions>();
Expected Result
When this package is working well:
required values are obvious because they use
Get<T>(),optional values are obvious because they use
GetOrDefault<T>(), anddownstream packages receive a clear configuration object instead of a loosely structured settings bag.
Next Step
Read Configuration Defaults if you want reusable defaults layered onto your settings model.
Read Data Sql if your next package needs database configuration.
Read Mailer or Logger File if your next concern is outbound mail or operational logging.
Notes
Get<T>()throws when a key is missing, which is useful for required settings.GetOrDefault<T>()is better suited to optional values.ConfigSettingsis intentionally simple, so it can be populated from JSON, environment variables, a database, or any custom source.If you need ready-made defaults for VersaTul packages, start with Configuration Defaults and then override values as needed.