Oip.Settings 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Oip.Settings --version 2.0.0
                    
NuGet\Install-Package Oip.Settings -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Oip.Settings" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Oip.Settings" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Oip.Settings" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Oip.Settings --version 2.0.0
                    
#r "nuget: Oip.Settings, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Oip.Settings@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Oip.Settings&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Oip.Settings&version=2.0.0
                    
Install as a Cake Tool

Oip.Settings

Application settings with an EF Core provider. Sources in order of priority:

  • Command line argument
  • Environment variables
  • JSON file
  • EF Core

Startup

  1. Create a settings class
public class AppSettings : BaseAppSettings<AppSettings>
{
    public string TestString { get; set; } = "test";
    public int TestInt { get; set; } = 1;
}
  1. Initialize settings with a ConnectionString from a JSON file, a command line argument or elsewhere
public class Program
{
    public static void Main(string[] args)
    {
        // Initialize settings 
        AppSettings.Initialize(args);

        var builder = WebApplication.CreateBuilder(args);
        // Add settings db context
        builder.Services.AddAppSettingsDbContext(AppSettings.Instance);
        
        var app = builder.Build();
        app.MapGet("/", () => $"AppSettings.Instance.TestInt: {AppSettings.Instance.TestInt}");

        app.Run();
    }
}

Connection string as a model

ConnectionString is written as a plain string in appsettings.json, but is available in code as a ConnectionModel:

{
  "ConnectionString": "XpoProvider=SQLite;Data Source=settings.db"
}
AppSettings.Instance.ConnectionString.Provider;                  // XpoProvider.SQLite
AppSettings.Instance.ConnectionString.NormalizeConnectionString; // Data Source=settings.db
AppSettings.Instance.ConnectionString.ConnectionString;          // XpoProvider=SQLite;Data Source=settings.db

ConnectionString is typed as ConnectionModel and is the single place where the parsed connection string lives. The former Provider, NormalizedConnectionString and Connection properties are removed, use ConnectionString.Provider and ConnectionString.NormalizeConnectionString instead.

ConnectionModel has a TypeConverter, so any own property of this type is bound from a plain string too:

public class AppSettings : BaseAppSettings<AppSettings>
{
    public ConnectionModel ReportConnection { get; set; } = default!;
}
{
  "ReportConnection": "XpoProvider=Postgres;Server=localhost;Database=report;"
}

Sensitive data logging

SensitiveDataLogging is a custom connection string parameter, just like XpoProvider. It is stripped from the normalized connection string and turns on EF Core sensitive data logging for the settings DbContext:

{
  "ConnectionString": "XpoProvider=SQLite;SensitiveDataLogging=true;Data Source=settings.db"
}
AppSettings.Instance.ConnectionString.SensitiveDataLogging;      // true
AppSettings.Instance.ConnectionString.NormalizeConnectionString; // Data Source=settings.db

Do not enable it in production: EF Core will then write parameter values into the log.

Running tests

Run all tests

dotnet test ./src/Oip.Settings.sln

Run tests that don't need external services

dotnet test ./src/Oip.Settings.sln --filter "TestCategory!=Integration"

Run only tests that need external services

dotnet test ./src/Oip.Settings.sln --filter "TestCategory=Integration"
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on Oip.Settings:

Package Downloads
Oip.Base

Package Description

Oip.Data

Package Description

Oip.Api

Package Description

Oip.Discussions

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 277 8/23/2026
2.0.0 95 8/22/2026
1.3.1 216 7/4/2026
1.3.0 2,072 12/20/2025
1.2.4 335 12/16/2025
1.2.3 554 12/5/2025
1.2.2 416 11/30/2025
1.2.1 167 11/29/2025
1.2.0 268 11/27/2025
1.1.10 258 11/22/2025
1.0.9 4,288 1/13/2025
1.0.8 197 12/24/2024
1.0.7 215 11/24/2024
1.0.6 286 6/1/2024
1.0.5 320 1/2/2024
1.0.4 250 12/31/2023
1.0.3 236 12/31/2023
1.0.2 225 12/31/2023
1.0.1 409 12/3/2023
1.0.0 245 11/30/2023