SCF: Simple configuration façade

Source: Internet
Author: User
Tags dotnet
SCF: Simple configuration façade

[中文版] Chinese

Simple Configuration facade, abbreviated as SCF. is a layer of abstraction between code and external configuration (properties files, environment variables, System/Command line parameters, Yaml files, and so on). The name is similar to another well-known component slf4j (simple Logging facade for Java), and the position in the configuration domain is the same as the slf4j (. NET analogue nlog) in the log domain.

SCF separates the code from the external configuration. The code uses a configuration item that does not care about where the configuration item is configured and how it is configured.

Usage
    • Java:github.com/mydotey/scf/tree/master/java

    • Dotnet:github.com/mydotey/scf/tree/master/dotnet

Example

Github.com/mydotey/scf-best-practice

Strong type of function

The core abstraction is a strongly typed property<k, V> key and value are strongly typed.

Secure configuration

The correctness of the external configuration can be checked from 1 value filter.

Dynamic configuration

The configuration can be dynamically changed. The value of the configuration item is automatically updated. The user can also add listener to monitor the configuration item changes.

Multiple configuration sources

Multiple configuration sources have different priority levels. The value of the configuration item is automatically calculated by the priority of the configuration source.

Can be extended

Scf-core only defines a set of interface abstractions and default implementations. All core concepts are extensible (Configuration Manager, configuration source, configuration items, and so on). Users are free to extend the default implementation or write their own implementations.

Some common extensions:

    • Scf-simple

    • Scf-labeled

    • Scf-yaml

    • Scf-apollo

Light weight

Using a wireless thread, only a small amount of memory is used to cache the configuration items.

Support Multithreading concurrency

Manager/property methods are thread-safe and can be used concurrently in multiple threads. Time is complicated to read as O (1), and Concurrenthashmap is the same.

Easy to use

Scf-simple implements the simplest and most common Property<String, String> scenarios: Properties file, Memory Map, System properties, env variables.

Reference:

    • Usage

    • Example

Core Concept configuration Item (property)

A configuration item is a hive that can be used independently in code , with 1 unique property Config and a strongly typed value.

code can listen for dynamic changes in configuration items. The value of a configuration item is automatically updated by Configuration Manager .

Configuration item configuration (property Config)

Configuration item configurations have the following components:

    • Key: Uniquely identifies 1 configuration items in 1 Configuration Manager . The most common type is String, or it can be another strongly typed object.

    • valuetype: The kind of the value of the configuration item.

    • Default value: Defaults to the configuration item . Use this default configuration if the configuration item is not provisioned in any of the configuration sources .

    • Value Converter: Value converter. Converts a value of 1 types to a value of another 1 type. For example, 1 configuration sources have configuration items <k, V1>, but the code needs configuration is <k, V2>, value converter <v1, v2> can automatically convert V1 value to V2 value.

    • Value Filter: Values filters. Used primarily to check the validity of the values taken from the configuration source.

Configure source (configuration sources)

1 configuration items can be configured in a variety of ways. Examples include memory dictionaries, properties files, environment variables, command line arguments, YAML files, and so on.

Multiple configuration methods can be used together. Each configuration method is 1 configuration sources. The configuration source is responsible for providing values for the configuration items.

Sometimes 1 configuration sources cannot provide a value to a configuration item, providing null (this configuration item is not considered to be configured).

    • The key for the configuration item cannot be identified by the configuration source. If key is a 1 strongly typed object { key: request.timeout, labels: { dc: aws-us-east1, app: 100000 } } , the configuration source only accepts a string type key.

    • Configuration items are not configured in the configuration source.

    • The value of the configuration item in the configuration source is type A, but the code requires the type B,propertyconfig No value converter can turn type A to type B, and the configuration source cannot automatically convert a to B.

Configuration Manager

Configuration Manager is the façade between the code and the external configuration . The code obtains configuration items from Configuration Manager , does not care where configuration items are configured, and how to configure them.

You can use only 1 configuration managers in 1 programs, or you can use several different managers. Different components can use different configuration managers, and Configuration Manager can also share/pass between different components.

Configuration Manager provides 2 APIs:

    • <K, V> Property<K, V> getProperty(PropertyConfig<K, V> config): For a stable configuration item with a stable key, returns 1 unique configuration items. Configuration Manager maintains this configuration item, automatically updates configuration values, and notifies configuration listener configuration items of changes. The code can maintain the obtained configuration item and reuse it multiple times.

    • <V> V getPropertyValue(PropertyConfig<K, V> config): Used for an unstable configuration item with an unstable key. For example, the visitor IP is part of the configuration key, unsure how many configuration items are in the program, and not determining which configuration item will be configured and when it will be configured.

Configure source and Configuration priorities

1 configuration managers can manage multiple configuration sources, and different configuration sources have different priority levels . Configuration Manager gets the configuration value from the configuration source by priority.

The relationship between core concepts

Core Logic

Developers
    • Qiang Zhao koqizhao@outlook.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.