Resolve By Name
Mark parameter as injected by name rather than type
Unless another name is provided, the paramater name is used for resolution.
To provide a named value of type T
to the dependency resolution, use a Tuple<String, T>
. (Which you can make with the construct "name" to value
).
Example:
class FrobnicatorClient(
@ResolveByName private val frobnicatorUrl: String
)
val context = resolveDependencies(
"frobnicatorUrl" to System.getenv("FROB_URL"),
FrobnicatorClient::class
)
context.get<String>("frobnicatorUrl")
Content copied to clipboard