ImportDeclaration class final

One entry of @Import that names code registering beans (a BeanRegistrar, ImportSelector or ImportBeanDefinitionRegistrar), recorded in BeanModule.registrars.

The generator writes one per imported class; you only create one when you build a module by hand. It tells the context how to create the registrar and when to run it.

create calls the class's no-argument constructor while the importing class is parsed, and only when the parse-phase conditions (those of the importing class) match. Then, as in Spring's configuration class parser and reader: a selector runs while the class is parsed, and the classes it selects are read before the importing class; a registrar runs right after the importing class's @Bean methods are registered, so later classes see its beans. The importing class is decided once, by its registerBean-phase conditions (such as Boot's @ConditionalOnBean) in class order, for itself, its @Bean methods and its imports. A skipped class runs no registrar, and the modules it selects are parsed but not registered, unless a kept class selects them too.

// A hand-written module whose only content is a registrar.
final module = BeanModule(
  'app',
  const [],
  registrars: [ImportDeclaration(MessagingRegistrar.new)],
);

Spring (Java):

@Configuration
@Import(MessagingRegistrar.class)
class AppConfig {}

Constructors

ImportDeclaration(Object create(), {List<Condition> conditions = const [], String? importer})
Declares an import whose registrar or selector is made by create.
const

Properties

conditions → List<Condition>
The conditions of the importing class; nothing is created when they do not match.
final
create → Object Function()
Creates the registrar or selector; called once, when it is needed.
final
hashCode → int
The hash code for this object.
no setterinherited
importer → String?
The importing class as library#Class (the source of its bean definition), which places the import among the module's classes. When null, the key of the ConditionGroup in conditions does. Without either, selectors run before the module's classes and registrars after them.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

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

Operators

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