findSubsystemByIdsChecked<TSubsystem extends Subsystem> static method

TSubsystem findSubsystemByIdsChecked<TSubsystem extends Subsystem>(
  1. String typeId,
  2. String classId
)

Finds a subsystem singleton or throws SubsystemNotFoundException if absent.

Implementation

static TSubsystem findSubsystemByIdsChecked<TSubsystem extends Subsystem>(
  String typeId,
  String classId,
) {
  final registry = findRegistryForTypeId(typeId);
  if (registry == null) {
    throw SubsystemNotFoundException(
      'No registry found for typeId $typeId',
      typeId: typeId,
      classId: classId,
    );
  }

  final singleton = registry.findByClassId(classId);
  if (singleton == null) {
    throw SubsystemNotFoundException(
      'No singleton found for classId $classId in typeId $typeId',
      typeId: typeId,
      classId: classId,
    );
  }

  if (singleton is! TSubsystem) {
    throw TypeError();
  }
  return singleton;
}