Skip to content

v3.1.0

Choose a tag to compare

@windischb windischb released this 19 Oct 11:19
· 64 commits to develop since this release
5a210fd

Interface Deserialization Support

This release adds support for deserializing interface-typed properties in configuration classes from JSON sources.

What's New

New API: setup.Interface<I>().DeserializeTo<T>()

Explicitly map interface properties to concrete types for JSON deserialization:

builder.AddCocoarConfiguration(rule => [
    rule.For<AppSettings>().FromEnvironment()
], setup => [
    setup.Interface<ILoggingConfig>().DeserializeTo<LoggingConfig>()
]);

Why This Matters

Configuration classes with interface properties (e.g., public ILoggingConfig Logging { get; set; }) would previously fail when loaded from JSON sources (files, environment variables, HTTP endpoints) because System.Text.Json cannot instantiate interfaces.

This commonly occurred when:

  • Setting logging configuration via environment variables (Logging__LogLevel__Default=Debug)
  • Using modular configuration with abstracted dependencies