RequiredAll constructor
const
RequiredAll()
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
, orbool
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.
Creates a RequiredAll annotation that, when applied to a class, signals the container to automatically inject all eligible fields.
Example
@Service()
@RequiredAll()
class EmailService {
late SmtpClient smtpClient; // Auto-injected
EmailService();
}
Implementation
const RequiredAll();