registerService<T extends StoppableService> method

T registerService<T extends StoppableService>(
  1. String id,
  2. T service, {
  3. bool permanent = false,
})

Registers a service under id.

If a service with the same id already exists, it is stopped first.

If permanent is true, the service will resist standard calls to pauseAllServices. It will only be paused if force is set to true. However, even permanent services are stopped when the controller is closed.

Implementation

T registerService<T extends StoppableService>(
  String id,
  T service, {
  bool permanent = false,
}) {
  _services[id]?.stop();
  _services[id] = service;
  if (permanent) {
    _permanentServices.add(id);
  } else {
    _permanentServices.remove(id);
  }
  return service;
}