RequiredAll class

An annotation used for dependency injection that automatically injects all eligible fields into a class.

This annotation is applied at the class level. It tells the dependency injection container to inject all non-ignored fields, without requiring individual @Autowired annotations.

  • Fields that are non-primitive types (classes, services, etc.) are automatically injected.
  • Fields that are nullable are treated as optional.
  • Primitive types like String, int, or bool are not automatically injected unless explicitly configured.

Example

@Service()
@RequiredAll()
class OrderService {
  late UserService userService;       // auto-injected
  late PaymentService paymentService; // auto-injected
  String config;                      // not injectable (primitive)

  OrderService();
}

void main() {
  print(orderService.userService);       // Injected instance
  print(orderService.paymentService);    // Injected instance
}

By default, all fields are required unless marked as nullable. This ensures strict correctness in service wiring.

Annotations
  • @Target.new({TargetKind.classType})

Constructors

RequiredAll()
An annotation used for dependency injection that automatically injects all eligible fields into a class.
const

Properties

annotationType Type
Returns the annotation _type of this annotation.
no setter
hashCode int
Returns a hash code consistent with equality definition.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

equals(Object other) bool
Checks whether the given object is logically equivalent to this annotation.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
Returns a string representation of this annotation.
inherited

Operators

operator ==(Object other) bool
Checks if this annotation is equal to another object.
inherited