-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow two-step parsing and decoding/binding
With this approach, if there are multiple prefixes and config classes to be bound, we parse the configuration only a single time, and decode multiple times.
- Loading branch information
1 parent
7bcd7ab
commit 450fc6a
Showing
4 changed files
with
131 additions
and
82 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
hoplite-core/src/main/kotlin/com/sksamuel/hoplite/ConfigBinder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.sksamuel.hoplite | ||
|
||
import com.sksamuel.hoplite.env.Environment | ||
import com.sksamuel.hoplite.internal.ConfigParser | ||
|
||
/** | ||
* Maintains a parsed configuration which can be used to bind to multiple configuration classes with a prefix. | ||
*/ | ||
class ConfigBinder( | ||
@PublishedApi internal val configParser: ConfigParser, | ||
@PublishedApi internal val environment: Environment?, | ||
) { | ||
/** | ||
* Binds the configuration to a configuration class, looking at with the given prefix. | ||
*/ | ||
inline fun <reified A : Any> bind(prefix: String): ConfigResult<A> = | ||
configParser.decode(A::class, environment, prefix) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters