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
Introspector, 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< definitions, {List<Object> >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<Introspection< introspections = const [], Map<Object> >String, EmbeddedResource> resources = const {}, Map<Type, bool Function(Object? value)> typeTests = const {}, Map<Type, int> typeDepths = const {}, Map<String, AopProxyFactory> aopProxies = const {}}) -
Creates a module named
namefromdefinitions; the collections are copied into unmodifiable lists and maps.
Properties
-
aopProxies
→ Map<
String, AopProxyFactory> -
The proxy factories of beans of library packages whose own modules
left them out (
AopProxyFactory.deferred), keyed by the definition'ssource: the application's generated module writes the proxy classes of those an aspect of the application may match, and the context puts each factory in the definition's place, whichever module is loaded first.final -
configurablePostConstruct
→ Map<
Type, void Function(Object bean)> -
The
@PostConstructmethods of the@Configurableclasses, keyed by class;initializeBeanruns them (the job of Spring'sCommonAnnotationBeanPostProcessor).final -
configurablePreDestroy
→ Map<
Type, void Function(Object bean)> -
The
@PreDestroymethods of the@Configurableclasses, keyed by class;destroyBeanruns them.final -
configurers
→ Map<
Type, BeanConfigurer> -
The generated injectors of the
@Configurableclasses, keyed by class;autowireBeanuses 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
@ComponentScandirectories.final -
introspections
→ List<
Introspection< Object> > -
The generated descriptions of the
@Introspectedclasses (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
@PropertySourcedeclarations of the module's classes, loaded before the module's definitions are decided, so their conditions see the properties.final -
registrars
→ List<
ImportDeclaration> -
The
@ImportedBeanRegistrar,ImportSelectorandImportBeanDefinitionRegistrarclasses. A selector's modules are read before the importing class, registrars run right after its@Beanmethods, 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 asresources:resources (see Resources), 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(Objectitself is 0): of two types a value is an instance of, the one with the greater depth is the closer. Without reflection aTypevalue alone cannot tell which of two types is the subtype; the generator reads it from the analyzer. Registered in the context's introspector (Introspector.typeDepth).final -
typeTests
→ Map<
Type, bool Function(Object? value)> -
A test
value is Tfor each typeTwritten in an annotation of the module's classes (@Transactional(noRollbackFor: [OutOfStock])), keyed by the type: without reflection, aTypevalue alone cannot tell whether an object is of a subtype. Registered in the context's introspector (Introspector.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