-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
github-actions[bot] edited this page Mar 24, 2026
·
3 revisions
Install the main package and the source generator from NuGet:
dotnet add package Dapplo.Ini
dotnet add package Dapplo.Ini.GeneratorThe generator package adds the Roslyn source generator that automatically creates a concrete
implementation class for each [IniSection]-annotated interface in your project.
Both packages target net48 and net10.0. No extra configuration is required for
.NET Framework projects — add the same two NuGet references and the generator works
identically.
Step 1 — Define the interface
using Dapplo.Ini;
[IniSection("App", Description = "Application settings")]
public interface IAppSettings : IIniSection
{
[IniValue(DefaultValue = "MyApp")]
string? AppName { get; set; }
[IniValue(DefaultValue = "8080")]
int Port { get; set; }
}Step 2 — Load at startup
The source generator creates AppSettingsImpl automatically. Reference it when
registering the section:
using var config = IniConfigRegistry
.ForFile("appsettings.ini")
.AddSearchPath(AppContext.BaseDirectory)
.RegisterSection<IAppSettings>(new AppSettingsImpl())
.Build();Step 3 — Use the settings
var settings = config.GetSection<IAppSettings>();
Console.WriteLine($"{settings.AppName} listening on port {settings.Port}");Step 4 — Save changes
settings.Port = 9090;
config.Save();The generator derives the concrete class name from the interface name:
| Interface name | Generated class name |
|---|---|
IAppSettings |
AppSettingsImpl |
IDbConfig |
DbConfigImpl |
IUserProfile |
UserProfileImpl |
ServerConfig (no leading I)
|
ServerConfigImpl |
The rule is: strip a leading I (if present) and append Impl.
- Ini-File-Format — full INI file syntax reference and examples
- Defining-Sections — full attribute reference
- Loading-Configuration — search paths, AppData, write target, constants files
- Loading-Life-Cycle — understand the exact resolution order