ComponentScan class

Generates a module with every bean declared in the directory of the annotated file and its subdirectories.

Dart cannot search the program for annotated classes at runtime, so the generator does it at build time (build_runner). Put @ComponentScan() on a top-level variable initialized with the generated module, which has the same name prefixed with $, then pass the variable to the context. A Spring Boot application uses @SpringBootApplication() instead, which scans too. A subdirectory with its own @ComponentScan belongs to that scan, and the enclosing scan imports its module instead of scanning its files again.

// lib/src/beans.dart: everything under lib/src/ is scanned.
import 'package:my_feature/src/beans.spring.dart';

@ComponentScan()
final BeanModule myFeatureBeans = $myFeatureBeans;

void main() {
  final context = ApplicationContext.run([myFeatureBeans]);
}

Spring (Java):

@Configuration
@ComponentScan("com.example.myfeature")
class MyFeatureConfig {}

var context = new AnnotationConfigApplicationContext(
    MyFeatureConfig.class);

Unlike Spring, which reads the classpath at startup, the filters are evaluated at build time too:

// Plugin classes are beans without @Component, stubs never are, and
// every bean is created on first use.
@ComponentScan(
  includeFilters: [
    Filter(type: FilterType.assignableType, classes: [Plugin]),
  ],
  excludeFilters: [Filter(type: FilterType.regex, pattern: ['.*Stub$'])],
  lazyInit: true,
)
final BeanModule myFeatureBeans = $myFeatureBeans;

Constructors

ComponentScan({List<Filter> includeFilters = const [], List<Filter> excludeFilters = const [], bool useDefaultFilters = true, bool lazyInit = false})
Scans the annotated file's directory; the arguments change what counts as a bean.
const

Properties

excludeFilters → List<Filter>
Classes matching one of these are never beans, whatever else says; their @Bean methods are skipped with them.
final
hashCode → int
The hash code for this object.
no setterinherited
includeFilters → List<Filter>
Classes matching one of these are beans even without @Component (an abstract class never is).
final
lazyInit → bool
Whether the scanned beans (components and their @Bean methods) are created on first use unless annotated @Lazy(false) (default false).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
useDefaultFilters → bool
Whether @Component (and annotations extending it) marks a bean (default true); with false only includeFilters do.
final

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