Caplin Trader 4.7.1

Class: module:caplin/core/ServiceRegistry

module:caplin/core/ServiceRegistry

Constructor

new module:caplin/core/ServiceRegistry()

The ServiceRegistry is used to allow a given application access to application services.

Services are typically registered or requested using an alias name, but older applications may still register and request using interfaces, which is also still supported. Applications that use aliases don't normally need to manually register services as these are created lazily upon first request, but will still need to manually register services that can't be created using a zero-arg constructor.

The ServiceRegistry is initialized as follows:

  1. The application invokes module:caplin/core/ServiceRegistry.initializeServices which causes all delayed readiness services to be created.
  2. Once module:caplin/core/ServiceRegistry.initializeServices has finished (once one of the call-backs fire), the application should then register any services that can't be created lazily using zero-arg constructors.
  3. The application can now start doing it's proper work.

Because blades aren't allowed to depend directly on classes in other blades, interface definitions are instead created for particular pieces of functionality, and blades can choose to register themselves as being providers of that functionality. The ServiceRegistry and the module:caplin/core/event/EventHub are both useful in this regard:

  • Many-To-One dependencies are resolved by having a single service instance available via the ServiceRegistry.
  • Many-To-Many dependencies are resolved by having zero or more classes register with the module:caplin/core/event/EventHub.

The ServiceRegistry is a static class and does not need to be constructed.

See:

Methods

(static) clear()

See:
  • module:br/ServiceRegistry.legacyClear

(static) deregisterService()

See:
  • module:br/ServiceRegistry.deregisterService

(static) getService()

See:
  • module:br/ServiceRegistry.getService

(static) initializeServices(callback, errback)

Registering with this method will notify when all services that implement module:caplin/core/DelayedReadinessService are ready to use.
Parameters:
Name Type Description
callback function the function that is called back when all services implementing module:caplin/core/DelayedReadinessService are ready for use.
errback function the function that is called back if there is an error during initialisation of any of the services, a string reason will be passed in as argument.
Throws:
if this method is called more than once.
Type
module:caplin/core/Error.ILLEGAL_STATE

(static) isServiceRegistered()

See:
  • module:br/ServiceRegistry.isServiceRegistered

(static) registerService()

See:
  • module:br/ServiceRegistry.registerService