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
  • API
  • General merging rules
  • Merging two value nodes
  • Merging two array nodes
  • Merging two object nodes
  • Related pages

Was this helpful?

Export as PDF
  1. Concepts and basics

Settings nodes merging

PreviousObject nodesNextSettings nodes scoping

Last updated 5 years ago

Was this helpful?

Merge is the operation of reducing two to one: left + right --> result.

Its primary use is to .

API

Each node type implements a Merge method that accept another node (right in our terms) and an instance of merge options with following properties:

Property

Values

Description

ObjectMergeStyle

Deep, Shallow

ArrayMergeStyle

Replace, Concat, Union, PerElement

is a handy public helper used to merge arbitrary nodes that handles nulls:

var result = SettingsNodeMerger.Merge(left, right, SettingsMergeOptions.Default);

General merging rules

  • If both nodes are null, the result is also null.

  • If one of the nodes is null, the non-null node wins:

    • left + null --> left

    • null + right --> right

  • If nodes are of different types, the right node always wins:

    • value + array --> array

    • array + object --> object

    • object + value --> value

  • If nodes are of same type, special rules apply. They are described in the next sections.

Right node always wins: left value + right value --> right value.

Replace style (default) always preserves the right array:

left array + right array --> right array.

Concat style produces an array containing elements from both arrays. All elements from the left array, then all elements from the second one, preserving order inside arrays.

[1, 2] + [2, 3] --> [1, 2, 2, 3]

Union style produces an array containing unique items from both arrays. The order is the same to Concat style.

[1, 2, 3] + [2, 3, 4] --> [1, 2, 3, 4]

Per element style produces an array containing items obtained by merging corresponding items (by index) from both arrays. If merged arrays have different children count, the "tail" of the longer array is preserved as-is.

[1, 2, 6] + [4, 5] --> [4, 5, 6]

Deep style (default) produces an object with union of the children from both nodes, then merges children with same names recursively.

{A:1} + {B:2} --> {A:1, B:2}

{A: {C:1}, B: {D:2}} + {A: {E:3}, B: {F:4}} --> {A: {C:1, E:3}, B: {D:2, F:4}}

Shallow style compares children of both nodes by names. If the sets of names match, regardless of order, merges the pairs of matching children recursively. Elsewise, just prefers to return the right node.

{A:1} + {B:2} --> {B:2}

{A:1} + {A:2} --> {A:2}

Related pages

Type of the merge procedure performed on . Deep is the default style.

Type of the merge procedure performed on . Replace is the default style.

Merging two

Merging two

Merging two

settings nodes
combine configuration sources
SettingsNodeMerger
value nodes
array nodes
object nodes
Settings nodes
Combine sources
object nodes
array nodes