Qualifier class

A Jetleaf annotation used to disambiguate injection targets when multiple candidate pods of the same type exist.

By default, Jetleaf performs type-based autowiring. When more than one pod matches the required type, you can use @Qualifier to select the correct one by:

  • Name → using name with the registered pod name.

When to Use

  • Multiple implementations of the same interface exist.
  • A pod must inject a specific instance.
  • You want to inject by name instead of type.

Example — Field Injection

abstract class Notifier {
  Future<void> send(String message);
}

@Service()
class NotificationService {
  @Autowired()
  @Qualifier("emailNotifier")
  late final Notifier emailNotifier;

  @Autowired()
  @Qualifier("smsNotifier")
  late final Notifier smsNotifier;

  Future<void> sendNotification(String message, NotificationType type) async {
    switch (type) {
      case NotificationType.email:
        await emailNotifier.send(message);
        break;
      case NotificationType.sms:
        await smsNotifier.send(message);
        break;
    }
  }
}

@Service("smsNotifier")
class SmsNotifier implements Notifier {
  @override
  Future<void> send(String message) async {
    // send SMS logic
  }
}

class EmailNotifier implements Notifier {
  @override
  Future<void> send(String message) async {
    // send email logic
  }
}

Example — Constructor Parameter

@Service()
class UserService {
  @Qualifier("emailNotifier") 
  final Notifier notifier;

  UserService(this.notifier);
}
Annotations
  • @Target.new({TargetKind.classType, TargetKind.field, TargetKind.parameter})

Constructors

Qualifier([String value = ''])
A Jetleaf annotation used to disambiguate injection targets when multiple candidate pods of the same type exist.
const

Properties

annotationType Type
Returns the annotation _type of this annotation.
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
value String
The pod name to qualify the injection target.
final

Methods

equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
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.

Operators

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