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

Was this helpful?

Export as PDF
  1. Advanced scenarios

Use shared provider instance

PreviousUse dynamic interfacesNextUse value substitutions

Last updated 4 years ago

Was this helpful?

Requires: .

class has a property named Default that serves as a global static source of IConfigurationProvider instance.

It's intended use case is self-sufficient configuration in libraries: library authors may not want to force their users to provide an IConfigurationProvider instance each time they're using library classes. Instead, these classes could just obtain a log from the shared property:

ConfigurationProvider.Default.SetupSourceFor<MyLibrarySettings>(...);

var settings = ConfigurationProvider.Default.Get<MyLibrarySettings>();

By default this property returns a singleton provider with default settings. It can be configured explicitly in the application:

var providerSettings = new ConfigurationProviderSettings { ... };
var provider = new ConfigurationProvider(providerSettings);

// Will return false if already explicitly configured:
ConfigurationProvider.TrySetDefault(provider);

Related pages

main module
Configuration provider
Configuration provider