EnumCraft.FeatureFlags.Json 0.2.1-preview

This is a prerelease version of EnumCraft.FeatureFlags.Json.
dotnet add package EnumCraft.FeatureFlags.Json --version 0.2.1-preview
                    
NuGet\Install-Package EnumCraft.FeatureFlags.Json -Version 0.2.1-preview
                    
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="EnumCraft.FeatureFlags.Json" Version="0.2.1-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EnumCraft.FeatureFlags.Json" Version="0.2.1-preview" />
                    
Directory.Packages.props
<PackageReference Include="EnumCraft.FeatureFlags.Json" />
                    
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 EnumCraft.FeatureFlags.Json --version 0.2.1-preview
                    
#r "nuget: EnumCraft.FeatureFlags.Json, 0.2.1-preview"
                    
#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 EnumCraft.FeatureFlags.Json@0.2.1-preview
                    
#: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=EnumCraft.FeatureFlags.Json&version=0.2.1-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=EnumCraft.FeatureFlags.Json&version=0.2.1-preview&prerelease
                    
Install as a Cake Tool

EnumCraft.FeatureFlags.Json

JSON file provider for EnumCraft.FeatureFlags.


Overview

EnumCraft.FeatureFlags.Json is the JSON file-based data provider for the EnumCraft feature flag system. It loads feature flag configuration from a JSON file, supports per-tenant overrides, and automatically reloads when the file changes — using a FileSystemWatcher with a polling fallback for reliability.

This package is part of the EnumCraft ecosystem:

Package Description
EnumCraft.Core Strongly-typed enums and flags (TypedEnum, TypedFlag)
EnumCraft.FeatureFlags Feature flag abstraction and resolution engine
EnumCraft.FeatureFlags.Json JSON file provider (this package)

Status

⚠️ This package is currently in preview. API surface is not yet stable and may change before v1.0.0.


Installation

dotnet add package EnumCraft.FeatureFlags.Json

Requirements

  • .NET Standard 2.0+ or .NET 8.0+
  • EnumCraft.FeatureFlags
  • EnumCraft.Core

Quick Start

using EnumCraft.FeatureFlags.Json;

var options = new JsonFeatureFlagProviderOptions
{
  DirectoryPath = AppDomain.CurrentDomain.BaseDirectory,
  FileName      = "AppFeatureFlag.json"   // name it to match your derived type
};

var provider = new JsonFeatureFlagProvider(options);

if(!AppFeatureFlag.TryConfigure(provider, out var error))
{
  Console.WriteLine($"Failed to configure flags: {error}");
  return;
}

Configuration Options

Property Default Description
DirectoryPath (required) Directory where the JSON file is located
FileName "FeatureFlags.json" Name of the JSON file
EnableAutoReload true Watch for file changes and reload automatically
DebounceMs 350 Minimum ms between reloads (prevents rapid re-reads)
PollMs 2000 Polling interval ms (fallback safety net)
MaxRetryAttempts 10 Max attempts to read file (handles mid-write states)
RetryDelayMs 100 Delay ms between retry attempts

FullPath is computed automatically from DirectoryPath + FileName.


JSON File Format

Name your JSON file to match your derived flag type (e.g., AppFeatureFlag.json).

{
  "global": {
    "DarkMode":        true,
    "NewDashboard":    true,
    "BetaReporting":   false,
    "MaintenanceMode": false
  },
  "tenants": {
    "1001": {
      "DarkMode":     false,
      "NewDashboard": false
    },
    "1002": {
      "BetaReporting": true
    }
  }
}

Resolution Order

  1. Tenant override — per-tenant value, if present
  2. Global override — global value from JSON, if present
  3. Default — constructor-defined fallback (isActiveDefault)

Auto-Reload Behavior

When EnableAutoReload is true (the default):

  • A FileSystemWatcher monitors the JSON file for changes
  • A polling timer runs as a fallback safety net
  • On successful reload, the Changed event is raised
  • On failed reload (malformed JSON, IO error), the previous snapshot is retained — no partial reads
  • The watcher is automatically recreated if it encounters a buffer overflow error

Disposal

JsonFeatureFlagProvider implements IDisposable. At application shutdown, dispose the provider to stop the watcher and polling timer cleanly:

provider.Dispose();

License

MIT — see LICENSE for details.


Author

Randel Bjorkquist

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1-preview 0 3/2/2026
0.2.0-preview 35 2/24/2026