registerConnections method

void registerConnections(
  1. DynamicPropertyRegistry registry
)

Adds the connection properties of the service connections to registry: each is read when the application asks for it, so it sees the mapped ports of the running container.

Implementation

void registerConnections(DynamicPropertyRegistry registry) {
  for (final name in serviceConnections) {
    final container = _container(name);
    if (container is! ServiceConnectionProperties) {
      throw StateError(
        '@ServiceConnection on $name: ${container.runtimeType} cannot say '
        'how to connect to it (PostgresContainer and KeycloakContainer '
        'can). Implement ServiceConnectionProperties, or set the '
        'properties in a @DynamicPropertySource method.',
      );
    }
    final source = container as ServiceConnectionProperties;
    for (final property in source.connectionProperties.keys) {
      registry.add(property, () => source.connectionProperties[property]);
    }
  }
}