Reusable configuration provider with DI and JSON storage for ClickOnce-compatible apps
License
—
Deps
2
Install Size
—
Vulns
✓ 0
Published
Aug 8, 2025
$ dotnet add package Common.ConfigA shared configuration library for desktop apps that supports per-application settings, ClickOnce-safe storage, and default config seeding from embedded JSON.
✔ Per-app configuration using %AppData%
✔ Strongly typed config class support
✔ Multi-class support in a single config file
✔ Loads defaults from embedded .defaults.json
✔ Safe across ClickOnce updates
✔ Uses System.Text.Json
✔ Fully DI-compatible with generic AppSettingsService<T>
Install via your internal NuGet feed:
dotnet add package Common.Config --version 1.0.x
// Register multiple classes if needed:
services.AddAppSettings<RefboxConfig>("RefboxManager", key: "RefboxConfig");
services.AddAppSettings<NetworkOptions>("RefboxManager", key: "NetworkOptions");
🧠 The softwareName controls the config path at:
%AppData%\OptonMedia\<SoftwareName>\settings.json
public class RefboxConfig
{
public string ReferenceBoxName { get; set; }
public int RetryAttempts { get; set; }
}
public class NetworkOptions
{
public string Hostname { get; set; }
public int Port { get; set; }
}
public class MyViewModel
{
private readonly AppSettingsService<RefboxConfig> _refboxSettings;
public MyViewModel(AppSettingsService<RefboxConfig> refboxSettings)
{
_refboxSettings = refboxSettings;
}
public void Update()
{
_refboxSettings.Settings.ReferenceBoxName = "WD999";
_refboxSettings.Save();
}
}
File: RefboxManager.defaults.json (Build Action: Embedded Resource)
{
"RefboxConfig": {
"ReferenceBoxName": "WD191",
"RetryAttempts": 3
},
"NetworkOptions": {
"Hostname": "localhost",
"Port": 8080
}
}
| Purpose | Location |
|---|---|
| Default config | Embedded as <SoftwareName>.defaults.json in your app |
| Runtime settings | %AppData%\OptonMedia\<SoftwareName>\settings.json |
.defaults.json%AppData%%AppData%%AppData% JSON filessoftwareName to AddAppSettings<T>Save() to persist changes//, /* */) are not supportedRefboxManagerHPWLSBurnInTestWeldMasterConfigToolEach uses this shared NuGet package with its own .defaults.json and config model.
/Common.Config
/IAppSettingsProvider.cs
/JsonAppSettingsProvider.cs
/AppSettingsService.cs
/ConfigServiceExtensions.cs