Value constructor
const
Value(
- Object value
Value annotation for property injection
This annotation injects property values into fields and parameters.
Example Usage:
PodExpression<String> expr = (context) {
return StandardPodCache("Hello, ${context.getPod("userName")}", "dart.core.String");
};
@Component()
class DatabaseService {
@Value('#{database.url}')
late final String databaseUrl;
@Value('#{database.timeout:30}') // Default value 30
late final int timeout;
@Value('#{database}')
late final String database;
@Value('#{database.enabled:true}')
late final bool enabled;
@Value('@{lifecycleProcessor}') // Reference to a pod
late final LifecycleProcessor lifecycleProcessor;
@Value("&{systemProperties['user.home']}") // Pod expression
late final String userHome;
@Value(CustomPodExpression<String>()) // Custom pod expression
late final String customValue;
}
@Configuration()
class AppConfig {
@Pod()
DataSource dataSource(
@Value('#{database.url}') String url,
@Value('#{database.username}') String username,
@Value('#{database.password}') String password
) {
return DataSource(url: url, username: username, password: password);
}
}
Implementation
const Value(this.value);