You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-1Lines changed: 14 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,7 @@ If you read the blog post linked above, you probably recognize that Configuratio
10
10
concept to construct incredibly complex configuration on the fly. But for the most common usage scenarios, a simple key/value replacement mechanism is all that
11
11
is needed. Most of the config builders in this project are such key/value builders.
12
12
13
+
#### mode
13
14
The basic concept of these config builders is to draw on an external source of key/value information to populate parts of the config system that are key/value in
14
15
nature. Specifically, the `appSettings` and `connectionStrings` sections receive special treatment from these key/value config builders. These builders can be
15
16
set to run in three different modes:
@@ -22,6 +23,7 @@ set to run in three different modes:
22
23
string. Any part of the raw xml string that matches the pattern __`${token}`__ is a candidate for token expansion. If no corresponding value is found in the
23
24
external source, then the token is left alone.
24
25
26
+
#### prefix
25
27
Another feature of these key/value Configuration Builders is prefix handling. Because full-framework .Net configuration is complex and nested, and external key/value
26
28
sources are by nature quite simple and flat, leveraging key prefixes can be useful. For example, if you want to inject both App Settings and Connection Strings into
27
29
your configuration via environment variables, you could accomplish this in two ways. Use the `EnvironmentConfigBuilder` in the default `Strict` mode and make sure you
@@ -41,10 +43,21 @@ so they can slurp up any setting or connection string you provide without needin
41
43
```
42
44
This way the same flat key/value source can be used to populate configuration for two different sections.
43
45
44
-
One final setting that is common among all of these key/value builders is `stripPrefix`. The code above does a good job of separating app settings from connection
46
+
#### stripPrefix
47
+
A related setting that is common among all of these key/value builders is `stripPrefix`. The code above does a good job of separating app settings from connection
45
48
strings... but now all the keys in AppSettings start with "AppSetting_". Maybe this is fine for code you wrote. Chances are that prefix is better off stripped from the
46
49
key name before being inserted into AppSettings. `stripPrefix` is a simple boolean value, and accomplishes just that. It's default value is `false`.
47
50
51
+
#### tokenPattern
52
+
The final setting that is shared between all KeyValueConfigBuilder-derived builders is `tokenPattern`. When describing the `Expand` behavior of these builders
53
+
above, it was mentioned that the raw xml is searched for tokens that look like __`${token}`__. This is done with a regular expression. `@"\$\{(\w+)\}"` to be exact.
54
+
The set of characters that matches `\w` is more strict than xml and many sources of config values allow, and some applications may need to allow more exotic characters
55
+
in their token names. Additionally there might be scenarios where the `${}` pattern is not acceptable.
56
+
57
+
`tokenPattern` allows developers to change the regex that is used for token matching. It is a simple string argument, and no validation is done to make sure it is
58
+
a well-formed non-dangerous regex - so use it wisely. The only real restriction is that is must contain a capture group. The entire regex must match the entire token,
59
+
and the first capture must be the token name to look up in the config source.
0 commit comments