bind<T> method
BindResult<T>
bind<T>(
- String name,
- TypeInfo<
T> target, { - BindHandler handler = BindHandler.defaultHandler,
Reads the properties at name as a value of type target.
name is in canonical form (lower case, dashes: app.read-timeout);
every relaxed spelling in the sources is found. The result says
whether anything was found (BindResult.isBound), so a missing
property can get a default. Throws a
ConfigurationPropertiesBindException that lists every property
that could not be converted.
handler is told about each property bound on the way and may change
the result or ignore failures.
final timeout = binder
.bind('app.timeout', const ClassType<Duration>())
.orElse(const Duration(seconds: 30));
Implementation
BindResult<T> bind<T>(
String name,
TypeInfo<T> target, {
BindHandler handler = BindHandler.defaultHandler,
}) {
final context = BindContext(this, handler: handler);
final value = context.bind(
ConfigurationPropertyName.of(name),
target,
existing: null,
);
context.throwIfFailed(name);
return identical(value, unbound)
? BindResult<T>._(null, isBound: false)
: BindResult<T>._(value, isBound: true);
}