BeanModule class final

Everything the generator found in one scanned directory: the bean definitions, plus the property files, imports and embedded resources that come with them.

Dart cannot scan a program for annotated classes at runtime, so @ComponentScan makes the generator write a module at build time, and the application passes its modules to the context. A context is built from a list of modules; a library ships its beans as a module of its own.

You normally never construct one: annotate a top-level variable with @ComponentScan() and pass it to the context. Write one by hand for a few beans in a test or a plugin. When the context loads a module, it first loads its imports, then adds its propertySources to the environment, then registers each definition whose conditions match and runs its registrars. configurers let autowireBean inject @Configurable classes, introspections go to the context's BeanIntrospector, and resources become resources: files.

@ComponentScan()
final BeanModule appBeans = $appBeans;

final context = ApplicationContext.run([coreBeans, appBeans]);

// A hand-written module with a fixed clock, for a test:
final testBeans = BeanModule('testBeans', [
  BeanDefinition<Clock>(
    name: 'clock',
    types: const [Clock],
    create: (_) => FixedClock(),
  ),
]);

Spring (Java) has no direct counterpart: a module is what classpath scanning plus @Configuration parsing would register.

var context = new AnnotationConfigApplicationContext();
context.scan("com.example.app");          // ≈ appBeans
context.registerBean("clock", Clock.class, FixedClock::new);
context.refresh();

Constructors

BeanModule(String name, Iterable<BeanDefinition<Object>> definitions, {List<PropertySourceDeclaration> propertySources = const [], List<BeanModule> imports = const [], List<ImportDeclaration> registrars = const [], Map<Type, BeanConfigurer> configurers = const {}, Map<Type, void Function(Object bean)> configurablePostConstruct = const {}, Map<Type, void Function(Object bean)> configurablePreDestroy = const {}, List<BeanIntrospection<Object>> introspections = const [], Map<String, EmbeddedResource> resources = const {}, Map<Type, bool Function(Object? value)> typeTests = const {}, Map<Type, int> typeDepths = const {}})
Creates a module named name from definitions; the collections are copied into unmodifiable lists and maps.

Properties

configurablePostConstruct → Map<Type, void Function(Object bean)>
The @PostConstruct methods of the @Configurable classes, keyed by class; initializeBean runs them (the job of Spring's CommonAnnotationBeanPostProcessor).
final
configurablePreDestroy → Map<Type, void Function(Object bean)>
The @PreDestroy methods of the @Configurable classes, keyed by class; destroyBean runs them.
final
configurers → Map<Type, BeanConfigurer>
The generated injectors of the @Configurable classes, keyed by class; autowireBean uses them.
final
definitions → List<BeanDefinition<Object>>
The bean definitions; each is registered only if its conditions match.
final
hashCode → int
The hash code for this object.
no setterinherited
imports → List<BeanModule>
Modules loaded before this one, such as those of imported configuration classes or of nested @ComponentScan directories.
final
introspections → List<BeanIntrospection<Object>>
The generated descriptions of the @Introspected classes (their properties and methods), used by data binding, validation and SpEL instead of reflection.
final
name → String
The module name, by convention the name of the annotated variable; shown in logs and errors.
final
propertySources → List<PropertySourceDeclaration>
The @PropertySource declarations of the module's classes, loaded before the module's definitions are decided, so their conditions see the properties.
final
registrars → List<ImportDeclaration>
The @Imported BeanRegistrar, ImportSelector and ImportBeanDefinitionRegistrar classes. A selector's modules are read before the importing class, registrars run right after its @Bean methods, and all are decided with the importing class (see ImportDeclaration).
final
resources → Map<String, EmbeddedResource>
The files of the package's lib/resources/, embedded by the generator and keyed by path; they are served as resources: resources (see ClasspathResources), which works in AOT, Flutter and the web too.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
typeDepths → Map<Type, int>
For each type of typeTests, the length of the longest chain of supertypes from it up to Object (Object itself is 0): of two types a value is an instance of, the one with the greater depth is the closer. Without reflection a Type value alone cannot tell which of two types is the subtype; the generator reads it from the analyzer. Registered in the context's introspector (BeanIntrospector.typeDepth).
final
typeTests → Map<Type, bool Function(Object? value)>
A test value is T for each type T written in an annotation of the module's classes (@Transactional(noRollbackFor: [OutOfStock])), keyed by the type: without reflection, a Type value alone cannot tell whether an object is of a subtype. Registered in the context's introspector (BeanIntrospector.isInstanceOf).
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited