Tenowg.MongoOptions 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package Tenowg.MongoOptions --version 1.0.2
                    
NuGet\Install-Package Tenowg.MongoOptions -Version 1.0.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="Tenowg.MongoOptions" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tenowg.MongoOptions" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Tenowg.MongoOptions" />
                    
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 Tenowg.MongoOptions --version 1.0.2
                    
#r "nuget: Tenowg.MongoOptions, 1.0.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 Tenowg.MongoOptions@1.0.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=Tenowg.MongoOptions&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Tenowg.MongoOptions&version=1.0.2
                    
Install as a Cake Tool
+ Please visit my [MongoOptions.Blazor](https://github.com/tenowg/MongoOptions.Blazor) Github, it will be a usuable project to add Razor components to manage your Config files

MongoOptions.Core 🍃

A high-performance, resilient configuration provider for .NET 10 that uses MongoDB as a backing store with built-in memory caching and data validation.

🚀 Features

  • Fluent Configuration: Set up in seconds with a clean, readable API.
  • Resilient Caching: Powered by IMemoryCache with "Stale-on-Failure" protection.
  • Keyed/Named Options: Support for multiple configuration instances (e.g., Tenant-specific settings).
  • Data Validation: Built-in support for Data Annotations to keep your DB clean.
  • Management API: Full CRUD support for managing configs via code (perfect for Blazor Admin UIs).

📦 Installation

dotnet add package Tenowg.MongoOptions

🛠️ Quick Start

1. Define your Settings POCO

Use standard Data Annotations for validation and our custom attribute for DB naming.

[Options(DatabaseName = "AppSettings", CollectionName = "FeatureToggle")]
public class FeatureSettings
{
    [Required]
    public string Theme { get; set; } = "Light";

    [Range(1, 100)]
    public int MaxRetries { get; set; } = 5;
}

The Options attribute is completely optional, Database and Collections can be generated by default.

2. Register in Program.cs

Use the Fluent API to hook everything up.

builder.Services.AddMongoConfiguration(config => 
{
    config.ConnectionString = "mongodb://localhost:27017";
    config.DatabaseName = "MyProductionApp";
})
.RegisterOptions<FeatureSettings>();

3. Usage

Inject IOptionsSnapshot<T> for automatic updates every request, or IOptionsMonitor<T> for real-time changes.

public class MyService(IOptionsSnapshot<FeatureSettings> settings)
{
    public void DoWork()
    {
        // Access the "Default" config
        var theme = settings.Value.Theme;

        // Access a "Named" config
        var tenantSettings = settings.Get("Tenant_A");
    }
}

🛡️ Validation & Resilience

This library ensures your app never runs with "garbage" data.

  1. Strict Lookups: If you request a named config that doesn't exist, it throws a KeyNotFoundException.
  2. Schema Protection: If a MongoDB document fails Data Annotation validation, an OptionsValidationException is thrown.
  3. Database Downtime: If MongoDB goes offline, the library will continue to serve cached data from the cache for 1 minute before trying the DB again, preventing "request spam."

🔧 Management (CRUD)

Use IConfigManager to build your own admin dashboard.

// Get all available config names for a type
var keys = await _configManager.GetKeys<FeatureSettings>();

// Save or Update
await _configManager.UpdateConfigAsync("NewTenant", mySettingsObject);

// Remove
await _configManager.RemoveConfig<FeatureSettings>("OldTenant");

// Clone
await _configManager.CloneConfigAsync<FeatureSettings>("SourceTenant", "TargetTenant");

📚 API Reference

MongoOptionsExtensions

  • AddMongoConfiguration(Action<MongoConfigurationOptions>): Sets up MongoDB client and returns a builder.
  • AddMongoOptions<T>(): Registers options for a type (alternative to builder).

MongoOptionsBuilder

  • RegisterOptions<T>(): Registers additional options types.

IConfigManager

  • UpdateConfigAsync<T>(T): Updates default config.
  • UpdateConfigAsync<T>(string, T): Updates named config.
  • GetKeys<T>(): Lists all config names for a type.
  • RemoveConfig<T>(string): Deletes a named config.
  • CloneConfigAsync<T>(string, string): Copies a config to a new name.

MongoConfigurationOptions

  • ConnectionString: MongoDB connection string.
  • DatabaseName: Default database name.
  • CacheSoftDuration: Cache refresh interval.
  • CacheHardDuration: Max cache lifetime.
  • CachePrefix: Cache key prefix.

OptionsAttribute

  • CollectionName: Custom collection name.
  • DatabaseName: Custom database name.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

If you encounter any issues or have questions, please open an issue on GitHub.

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 (1)

Showing the top 1 NuGet packages that depend on Tenowg.MongoOptions:

Package Downloads
Tenowg.MongoOptions.Blazor

A Blazor library to use with MongoOptions.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 101 5/15/2026
1.1.2-alpha.0.6 48 5/15/2026
1.1.1 116 2/20/2026
1.1.0 129 2/6/2026
1.0.2 139 2/1/2026
1.0.1 132 2/1/2026
1.0.0 118 1/31/2026