Constructs the instance backing a facility and identifies that facility across lookups and bindings.
Doubling as the identity means services are looked up and bound by reference, so a service must be declared in a
single module and re-exported by reference only, as wrapping it in a new function forks the identity and silently
declares a second service.
Construction must be synchronous and free of I/O, deferring such work to the instance's own methods; an
implementation bound to a service is exempt, as it is constructed ahead of the job.
Important
Construction is all or nothing, as a transaction is: a run either records an instance or rolls back, leaving
nothing of what it had already done. A factory letting an error through must first release whatever it holds and
undo whatever it has changed, then rethrow that same error: an error raised by a lookup of its own reaches the
caller unchanged, never replaced by another or swallowed in favour of an alternative, as it may be the signal
unwinding the construction: one reaching a service the execution is not yet ready to hand over is abandoned where
it stands and run again from the start. Nothing tells such a run from a first one, so a second must be
indistinguishable from a first.
Tip
Performing every lookup before constructing anything discharges the requirement outright: a factory holding
nothing at the point an unwinding error can reach it has nothing to release and nothing to undo.
Releasing whatever the instance holds is opt-in: an instance exposing a callable Symbol.asyncDispose or
Symbol.dispose member, either its own or inherited, is disposed as the execution ends, as detailed under
Executor; any other instance is left as it is.
Important
Because the constructing function carries the identity, naming a service links its default implementation: the
module declaring a service must stay import-light, requiring heavy clients lazily inside the default
implementation rather than at module level.
Type Parameters
TextendsDefined
The type of the constructed instance, undefined excepted, as it marks a service under construction
Service factory.
Constructs the instance backing a facility and identifies that facility across lookups and bindings.
Doubling as the identity means services are looked up and bound by reference, so a service must be declared in a single module and re-exported by reference only, as wrapping it in a new function forks the identity and silently declares a second service.
Construction must be synchronous and free of I/O, deferring such work to the instance's own methods; an implementation bound to a service is exempt, as it is constructed ahead of the job.
Construction is all or nothing, as a transaction is: a run either records an instance or rolls back, leaving nothing of what it had already done. A factory letting an error through must first release whatever it holds and undo whatever it has changed, then rethrow that same error: an error raised by a lookup of its own reaches the caller unchanged, never replaced by another or swallowed in favour of an alternative, as it may be the signal unwinding the construction: one reaching a service the execution is not yet ready to hand over is abandoned where it stands and run again from the start. Nothing tells such a run from a first one, so a second must be indistinguishable from a first.
Performing every lookup before constructing anything discharges the requirement outright: a factory holding nothing at the point an unwinding error can reach it has nothing to release and nothing to undo.
Releasing whatever the instance holds is opt-in: an instance exposing a callable
Symbol.asyncDisposeorSymbol.disposemember, either its own or inherited, is disposed as the execution ends, as detailed under Executor; any other instance is left as it is.Because the constructing function carries the identity, naming a service links its default implementation: the module declaring a service must stay import-light, requiring heavy clients lazily inside the default implementation rather than at module level.