Qualifier constructor

const Qualifier([
  1. String value = ''
])

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);
}

Implementation

const Qualifier([this.value = '']);