ToonNet.AspNetCore 1.4.0

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

ToonNet.AspNetCore

ASP.NET Core integration for ToonNet serialization

.NET NuGet Downloads Status


๐Ÿ“ฆ What is ToonNet.AspNetCore?

ToonNet.AspNetCore provides seamless integration of ToonNet serialization with ASP.NET Core:

  • โœ… Dependency Injection - Register ToonParser, ToonEncoder, and options
  • โœ… Configuration Binding - Load settings from appsettings.json
  • โœ… Options Validation - Fail-fast on invalid configuration
  • โœ… TOON Configuration Provider - Read TOON files as configuration source
  • โœ… Middleware Ready - Foundation for MVC formatters and middleware

Perfect for:

  • ๐ŸŒ Web APIs - Serve TOON-formatted responses
  • โš™๏ธ Configuration - Load TOON config files
  • ๐Ÿ”ง DI Integration - Inject ToonParser/Encoder into services
  • ๐Ÿ“Š Options Pattern - Configure ToonNet via appsettings.json

๐Ÿš€ Quick Start

Installation

# Core package (required)
dotnet add package ToonNet.Core

# ASP.NET Core integration
dotnet add package ToonNet.AspNetCore

# For MVC formatters (optional)
dotnet add package ToonNet.AspNetCore.Mvc

Basic Setup - Default Options

using ToonNet.AspNetCore;

var builder = WebApplication.CreateBuilder(args);

// Register ToonNet services with default options
builder.Services.AddToon();

var app = builder.Build();
app.Run();

This registers:

  • ToonParser (singleton)
  • ToonEncoder (singleton)
  • ToonOptions (IOptions<ToonOptions>)
  • ToonSerializerOptions (IOptions<ToonSerializerOptions>)

โš™๏ธ Configuration

appsettings.json:

{
  "ToonNet": {
    "ToonOptions": {
      "IndentSize": 2,
      "MaxDepth": 64,
      "PreferInlineArrays": true,
      "PreferInlineObjects": false,
      "MaxInlineArrayLength": 80,
      "Delimiter": ",",
      "StrictMode": false,
      "AllowExtendedLimits": false
    },
    "ToonSerializerOptions": {
      "IncludeReadOnlyProperties": false,
      "MaxDepth": 64,
      "AllowExtendedLimits": false
    }
  }
}

Program.cs:

var builder = WebApplication.CreateBuilder(args);

// Bind configuration from appsettings.json
builder.Services.AddToon(builder.Configuration);

var app = builder.Build();
app.Run();

Using Delegate Configuration

builder.Services.AddToon(toonOptions =>
{
    toonOptions.IndentSize = 4;
    toonOptions.PreferInlineArrays = true;
    toonOptions.MaxDepth = 100;
}, serializerOptions =>
{
    serializerOptions.IncludeReadOnlyProperties = false;
    serializerOptions.MaxDepth = 100;
});

Hybrid Approach (Configuration + Delegate)

// Load from config + override specific values
builder.Services.AddToon(
    builder.Configuration,
    toonOptions =>
    {
        // Override specific settings
        toonOptions.IndentSize = 4;
    },
    serializerOptions =>
    {
        serializerOptions.IncludeReadOnlyProperties = true;
    }
);

๐Ÿ“– Configuration Options

ToonOptions

Controls TOON format encoding behavior:

Option Type Default Description
IndentSize int 2 Number of spaces per indentation level
MaxDepth int 64 Maximum nesting depth
PreferInlineArrays bool true Use inline format for simple arrays
PreferInlineObjects bool false Use inline format for simple objects
MaxInlineArrayLength int 80 Max character length for inline arrays
Delimiter char , Array item delimiter
StrictMode bool false Enable strict parsing rules
AllowExtendedLimits bool false Allow depths beyond 64 levels

ToonSerializerOptions

Controls C# object serialization behavior:

Option Type Default Description
IncludeReadOnlyProperties bool false Include read-only properties
MaxDepth int 64 Maximum object graph depth
AllowExtendedLimits bool false Allow depths beyond 64 levels

๐ŸŽฏ Usage Patterns

Pattern 1: Inject ToonParser/Encoder

public class ToonService
{
    private readonly ToonParser _parser;
    private readonly ToonEncoder _encoder;
    private readonly ILogger<ToonService> _logger;

    public ToonService(
        ToonParser parser, 
        ToonEncoder encoder,
        ILogger<ToonService> logger)
    {
        _parser = parser;
        _encoder = encoder;
        _logger = logger;
    }

    public ToonDocument ParseToon(string toonString)
    {
        try
        {
            return _parser.Parse(toonString);
        }
        catch (ToonParseException ex)
        {
            _logger.LogError(ex, "Failed to parse TOON");
            throw;
        }
    }

    public string EncodeToon(ToonDocument document)
    {
        return _encoder.Encode(document);
    }
}

// Register service
builder.Services.AddScoped<ToonService>();

Pattern 2: Inject Options

using Microsoft.Extensions.Options;

public class ConfigAnalyzer
{
    private readonly ToonOptions _toonOptions;
    private readonly ToonSerializerOptions _serializerOptions;

    public ConfigAnalyzer(
        IOptions<ToonOptions> toonOptions,
        IOptions<ToonSerializerOptions> serializerOptions)
    {
        _toonOptions = toonOptions.Value;
        _serializerOptions = serializerOptions.Value;
    }

    public void LogConfiguration()
    {
        Console.WriteLine($"Indent Size: {_toonOptions.IndentSize}");
        Console.WriteLine($"Max Depth: {_toonOptions.MaxDepth}");
        Console.WriteLine($"Include Read-Only: {_serializerOptions.IncludeReadOnlyProperties}");
    }
}

Pattern 3: Use with ToonSerializer

using ToonNet.Core.Serialization;
using Microsoft.Extensions.Options;

public class DataService
{
    private readonly ToonSerializerOptions _options;

    public DataService(IOptions<ToonSerializerOptions> options)
    {
        _options = options.Value;
    }

    public string SerializeData<T>(T data)
    {
        // Use configured options
        return ToonSerializer.Serialize(data, _options);
    }

    public T DeserializeData<T>(string toonString)
    {
        return ToonSerializer.Deserialize<T>(toonString, _options);
    }
}

๐Ÿ“‚ TOON Configuration Provider

Load TOON files as ASP.NET Core configuration sources:

Create TOON Configuration File

appsettings.toon:

Database:
  ConnectionString: Server=localhost;Database=mydb
  Timeout: 30
  EnableRetry: true

Logging:
  Level: Information
  Console:
    Enabled: true
  File:
    Path: logs/app.log
    MaxSize: 10485760

Features:
  EnableCache: true
  CacheExpiry: 3600

Register TOON Configuration Provider

var builder = WebApplication.CreateBuilder(args);

// Add TOON file as configuration source
builder.Configuration.AddToonFile("appsettings.toon", optional: false, reloadOnChange: true);

// Register ToonNet services
builder.Services.AddToon(builder.Configuration);

var app = builder.Build();

// Access configuration
var connectionString = builder.Configuration["Database:ConnectionString"];
var logLevel = builder.Configuration["Logging:Level"];

Configuration Provider Features

// Multiple TOON files
builder.Configuration
    .AddToonFile("appsettings.toon")
    .AddToonFile($"appsettings.{env}.toon", optional: true);

// With environment variables
builder.Configuration
    .AddToonFile("config.toon")
    .AddEnvironmentVariables();

// Reload on change
builder.Configuration.AddToonFile(
    "settings.toon",
    optional: false,
    reloadOnChange: true  // Auto-reload when file changes
);

โœ… Validation

ToonNet.AspNetCore uses Options Validation to ensure configuration is valid:

Automatic Validation

// Validation happens at startup
builder.Services.AddToon(builder.Configuration);

// If configuration is invalid, app will fail to start with clear error message

Custom Validation

builder.Services.AddToon(builder.Configuration)
    .Validate(options => 
    {
        if (options.IndentSize < 1 || options.IndentSize > 8)
            return false;
        return true;
    }, "IndentSize must be between 1 and 8");

Validation Rules (Built-in)

  • IndentSize: Must be 1-8
  • MaxDepth: Must be 1-1024 (or 1-64 if AllowExtendedLimits=false)
  • MaxInlineArrayLength: Must be 1-1024
  • Delimiter: Must be a valid character

๐Ÿ”’ Thread-Safety

  • ToonSerializer methods are safe to call concurrently across threads.
  • Shared metadata/name caches use ConcurrentDictionary for concurrent access.
  • Cache entries are created on demand and retained for the process lifetime (no eviction).
  • Do not mutate a single ToonSerializerOptions instance concurrently across threads.

Core:

Extensions:

Web Integration:

Development:


๐Ÿ“š Documentation


๐Ÿงช Testing

# Run ASP.NET Core integration tests
cd tests/ToonNet.Tests
dotnet test --filter "Category=AspNetCore"

๐Ÿ“‹ Requirements

  • .NET 8.0 or later
  • ASP.NET Core 8.0+
  • ToonNet.Core

๐Ÿ“„ License

MIT License - See LICENSE file for details.


๐Ÿค Contributing

Contributions welcome! Please read CONTRIBUTING.md first.


Part of the ToonNet serialization library family.

Product Compatible and additional computed target framework versions.
.NET 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 (1)

Showing the top 1 NuGet packages that depend on ToonNet.AspNetCore:

Package Downloads
ToonNet.AspNetCore.Mvc

ASP.NET Core MVC integration for ToonNet. Provides input/output formatters for TOON format support in MVC controllers and Web APIs.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 130 2/8/2026
1.3.0 120 2/4/2026
1.2.0 121 2/1/2026
1.1.0 124 1/28/2026
1.0.0 122 1/12/2026

v1.4.0: Updated to support ToonNet.Core 1.4.0 streaming features.