ServiceRegistry class

Mechanism to release port-consuming resources like database connections and streams.

Aqueduct applications may open many streams as part of their operation. During testing, an application must be shut down gracefully to complete the tests - this includes shutting down open streams like database connections so that the isolate can complete. This class allows closable instances to be registered for shutdown. When shutdown of an application occurs, the registered objects are closed, thus releasing the resource they consume that prevent the isolate from shutting down.

There is one registry per isolate. The order in which registrations are shut down is undefined. close triggers shutdown and is automatically invoked by Application.stop.

Built-in Aqueduct types that open a stream, like PersistentStore, automatically register themselves when instantiated. If you are unsure whether an object has been registered for shutdown, you may add it - multiple additions have no effect on the registry, as they will only be shutdown once.

Constructors

ServiceRegistry()

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

close() Future
Closes all registered resources. [...]
register<T>(T object, FutureOr onClose(T object)) → T
Adds an object to the registry, registered objects are closed when close is invoked. [...]
unregister(dynamic object) → void
Removes an object from the registry.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Properties

defaultInstance ServiceRegistry
final