NCode.PropertyBag 2.1.2

Prefix Reserved
dotnet add package NCode.PropertyBag --version 2.1.2
                    
NuGet\Install-Package NCode.PropertyBag -Version 2.1.2
                    
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="NCode.PropertyBag" Version="2.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NCode.PropertyBag" Version="2.1.2" />
                    
Directory.Packages.props
<PackageReference Include="NCode.PropertyBag" />
                    
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 NCode.PropertyBag --version 2.1.2
                    
#r "nuget: NCode.PropertyBag, 2.1.2"
                    
#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 NCode.PropertyBag@2.1.2
                    
#: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=NCode.PropertyBag&version=2.1.2
                    
Install as a Cake Addin
#tool nuget:?package=NCode.PropertyBag&version=2.1.2
                    
Install as a Cake Tool

NCode.PropertyBag

CI Coverage Target framework License

Strongly typed property bags for .NET: store and read values by type-safe keys, override a value for a scope, clone a bag, and create bags through dependency injection.

This package holds the bag, PropertyBagDictionary, its factories and AddPropertyBag(); the interfaces and keys are in NCode.PropertyBag.Abstractions, which it depends on.

Installation

dotnet add package NCode.PropertyBag

The target frameworks are the ones the package's .csproj declares; they are listed on nuget.org's Frameworks tab and shown by the badge above. CHANGELOG.md records when a framework is added or dropped and which release line to stay on.

Example

Define each key once, typically as a static readonly field:

using NCode.PropertyBag;

public static class UserKeys
{
    public static readonly PropertyBagKey<string> UserName = new("UserName");
    public static readonly PropertyBagKey<int> UserAge = new("UserAge");
}

Then create a bag, store values and read them back:

var propertyBag = PropertyBagFactory.Create();

propertyBag.SetValue(UserKeys.UserName, "Alice").SetValue(UserKeys.UserAge, 30);

if (propertyBag.TryGetValue(UserKeys.UserName, out var userName))
{
    Console.WriteLine($"User: {userName}"); // User: Alice
}

Scope sets a value until the returned scope is disposed, then restores the value the key held before, or removes the key when it held none:

var cultureKey = new PropertyBagKey<string>("Culture");
propertyBag.SetValue(cultureKey, "en-US");

string? inScope;
using (propertyBag.Scope(cultureKey, "fr-FR"))
{
    propertyBag.TryGetValue(cultureKey, out inScope); // "fr-FR"
}

propertyBag.TryGetValue(cultureKey, out var afterScope); // "en-US" again

Dependency injection

AddPropertyBag() registers IPropertyBagFactory as a singleton, keeping one the application registered first:

var services = new ServiceCollection();
services.AddPropertyBag();
services.AddSingleton<RequestContextFactory>();

Learn more

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (18)

Showing the top 5 NuGet packages that depend on NCode.PropertyBag:

Package Downloads
NCode.Identity.Jwt.Abstractions

Package Description

NCode.Identity.OpenId.Client.Abstractions

Package Description

NCode.Identity.OpenId.Authentication.Abstractions

Package Description

NCode.Identity.Jwt

Package Description

NCode.Identity.Bff.Abstractions

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.2 443 11/22/2026
2.1.1 208 11/21/2026
2.1.0 161 11/20/2026
2.0.2 78 11/20/2026
2.0.1 86 11/20/2026
2.0.0 94 11/20/2026
1.2.0 3,406 1/19/2026
1.1.1 146 1/19/2026
1.1.0 141 1/19/2026
1.0.1 144 1/19/2026
1.0.0 143 1/19/2026