Vostok.Configuration
HomeQuickstartConcepts and basicsBasic scenarios
  • Home
  • Quickstart
  • Concepts and basics
    • Settings nodes
      • Value nodes
      • Array nodes
      • Object nodes
    • Settings nodes merging
    • Settings nodes scoping
    • Binding nodes to models
    • Configuration sources
    • Configuration provider
    • Caching and performance
    • Error handling
  • Modules
    • Abstractions
    • Configuration
    • Sources
    • Sources.CC
    • Sources.Json
    • Sources.Yaml
    • Sources.Xml
    • Sources.Vault
    • Logging
    • Microsoft
  • Sources
    • Constant sources
    • Object source
    • XML sources
    • YAML sources
    • JSON sources
    • Vault source
    • ClusterConfig source
    • Command line source
    • Environment variables source
  • Binders
    • Primitives
    • Collections
    • Classes and structs
    • Constructor injection
  • Basic scenarios
    • Assign sources to types
    • Obtain settings from provider
    • Observe settings via provider
    • Print settings
    • Log settings updates
    • Log errors
    • Combine sources
    • Scope sources
    • Make settings secret
    • Make settings required
  • Advanced scenarios
    • Use name aliases
    • Use dynamic interfaces
    • Use shared provider instance
    • Use value substitutions
    • Nest sources
    • Freeze sources
    • Transform sources
    • Create custom sources
    • Apply custom validators
    • Apply custom binders
    • Apply source data to existing object
    • Print contents of a source
Powered by GitBook
On this page
  • How it works
  • Settings tree navigation
  • Required and optional members
  • Model requirements
  • Binder requirements
  • Node requirements
  • Related pages

Was this helpful?

Export as PDF
  1. Binders

Classes and structs

PreviousCollectionsNextConstructor injection

Last updated 3 years ago

Was this helpful?

How it works

The binder starts off by creating an instance of the bound type with default values of public fields and properties (the same way as Activator.CreateInstance does) and then recursively binds the value of every field and property to a corresponding subsection of the settings tree. See page for a step-by-step illustration of this process.

Fields and properties don't have to be mutable: readonly fields and properties with private setters (or even without one) are fine.

Following members are ignored: indexers, constants, static and non-public fields and properties, computed properties without backing fields.

Nested classes and are supported without restrictions.

Settings tree navigation

When binding a field or property value, the settings tree is to the member name. This imposes a requirement to synchronize naming in configuration data provided by and models in the application code. In order to bind a model property named Timeout from a section of JSON file, this section must contain a property with the same name (barring case).

Model                             JSON data source

class Settings                    {
{
    TimeSpan Timeout { get; } -------> "timeout": "2 seconds",
    
    int Parallelism { get; }  -------> "parallelism": 32
}                                 }

allow to decouple property names from configuration data names.

Required and optional members

Model requirements

Binder requirements

Binders are required for all public fields and properties.

Node requirements

Related pages

By default all fields and properties are treated as optional: they are just left with default values if no data could be found in the settings tree (default values may come from field and property initializers). It's possible to though. Required members with no data in the settings tree cause the binding process to fail and produce an exception.

Model classes must either have a parameterless constructor, a constructor with a single parameter, or have an OmitConstructorsAttribute (which allows , therefore, no default parameters are present).

Only are supported.

binding nodes to models
collections
scoped
sources
Name aliases
make members required
creating an uninitialized object
object nodes
Binding nodes to models
Make settings required
Make settings secret
Use name aliases
Apply custom binders