Skip to content

Connectum API Reference / @connectum/core / defineLazyService

Function: defineLazyService() ​

defineLazyService<S>(descriptor, factory, options?): ServiceDefinition

Defined in: packages/core/src/defineService.ts:108

Define a service whose handlers (and their dependencies) are created lazily.

factory runs only when the service is actually mounted locally — i.e. when it is in enabledServices (or enabledServices is undefined). A service routed to a remote process never instantiates its local dependencies. Useful for DI-heavy monoliths where wiring a service is expensive.

factory must be synchronous and return the handlers object (see defineService); an async factory, or a result that is not an object of functions, throws a TypeError naming the service when the factory runs.

factory runs once per server: the HTTP adapter, server.localClient and ctx.call all reach the same instance. The same definition mounted on two servers yields one instance per server.

Type Parameters ​

S ​

S extends DescService

Parameters ​

descriptor ​

S

factory ​

() => ConnectumServiceImpl<S>

options? ​

Partial<UniversalHandlerOptions>

Returns ​

ServiceDefinition