Class
caplin.core

ServiceRegistry

The ServiceRegistry is used to allow concrete class instances to register as the provider of a particular service within a given application.

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

  • Many-To-One dependencies are resolved by having a single class register with the ServiceRegistry.
  • Many-To-Many dependencies are resolved by having zero or more classes register with the caplin.core.event.EventHub.
Example: A button in the application needs to toggle the display of a list of Alerts. The method to display this list is in the Alerts blade but the application cannot call it directly. The caplin Alert library contains a interface caplin.alerts.AlertsService describing the methods that Alerts blade exposes, which includes the method openAlertManagerDialog. The caplin.alerts.AlertsService interface is implemented by caplinb.alerts.view.AlertsService which registers itself with the caplin.core.ServiceRegistry using the name of the interface it implements. When the AlertsDrawerButtonHandler class in caplinx (which is responsible for showing the list), it calls into the caplin.core.ServiceRegistry and gets a instance of caplinb.alerts.view.AlertsService using the interface name as a key. AlertsDrawerButtonHandler can then use this instance to call openAlertManagerDialog and toggle the display of the list.

Constructor Summary

Attributes Name and Description
caplin.core.ServiceRegistry()

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

Method Summary

Attributes Name and Description
<static> void deregisterService(String sInterface)

De-register an object that has previously been registered using registerService.

<static> Object getService(caplin.core.ServiceRegistry sInterface)

Retrieve the object responsible for implementing the given interface within the application.

<static> boolean isServiceRegistered(caplin.core.ServiceRegistry sInterface)

Determine whether a service has been registered for a given interface.

<static> void registerService(String sInterface, Object oServiceInstance)

Register an object that will be responsible for implementing the given interface within the application.

Constructor Detail

caplin.core.ServiceRegistry()

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

Method Detail

<static> void deregisterService(String sInterface)

De-register an object that has previously been registered using registerService.

Parameters
String sInterface The interface the service being de-registered implements.

<static> Object getService(caplin.core.ServiceRegistry sInterface)

Retrieve the object responsible for implementing the given interface within the application.

Parameters
caplin.core.ServiceRegistry sInterface The interface the service instance being retrieved implements.
Throws
caplin.core.Error
If no service has been registered for the given interface.

<static> boolean isServiceRegistered(caplin.core.ServiceRegistry sInterface)

Determine whether a service has been registered for a given interface.

Parameters
caplin.core.ServiceRegistry sInterface The name of the interface being queried.

<static> void registerService(String sInterface, Object oServiceInstance)

Register an object that will be responsible for implementing the given interface within the application.

Parameters
String sInterface The interface the service being registered implements.
Object oServiceInstance The object responsible for implementing the given interface.