PropertySource<T> constructor

PropertySource<T>(
  1. String name,
  2. T source
)

A base abstraction representing a source of key-value properties, such as maps, environment variables, or configuration files.

Each PropertySource has a unique name and a backing source of type T, which holds the actual data. Concrete subclasses implement lookup behavior using containsProperty and getProperty.

Common implementations include:

This abstraction allows a flexible property resolution system where multiple sources can be layered and resolved by a resolver such as PropertySourcesPropertyResolver.

Example usage:

class MyEnvSource extends PropertySource<Map<String, String>> {
  MyEnvSource(String name, Map<String, String> source) : super(name, source);

  @override
  bool containsProperty(String name) => source.containsKey(name);

  @override
  Object? getProperty(String name) => source[name];
}

final env = MyEnvSource('env', {'APP_ENV': 'prod'});
print(env.getProperty('APP_ENV')); // prod

Implementation

PropertySource(this.name, this.source);