class ServiceContext
A container of named services, part of the global application context.
class ServiceContext extends ManagedObject
Description
This class is a container for named services, which should be accessible by the rest of the application. Services can be set, unset, and replaced using the global service context.
- Use the add() method to add or update a service by ID. The service must be an instance of Service with a valid
id
property. The service is automatically attached to the ServiceContext instance. An alias of this method is available as app.addService(). - Use the get() method to retrieve a service by ID, if one is currently registered.
- Unlink a service to remove (unregister) it.
- Use the Activity.observeService() or Service.observeService() methods to observe a particular service by ID and handle change events.
Instance Members
- get(id)Returns a single service instance by ID, if registered.
- getAll()Returns an array of all currently registered services.
- add(service)Adds the specified service.
- clear()Removes all services that are currently registered.
Inherited Members
- emit(event)Emits an event, immediately calling all event handlers.
- emitChange(name?, data?)Emits a change event, an instance of ManagedChangeEvent.
- listen(handler)Adds a handler for all events emitted by this object.
- isUnlinked()Returns true if the object has been unlinked.
- unlink()Unlinks this managed object.
- beforeUnlink() protectedA method that’s called immediately before unlinking an object, can be overridden.
- attach(target, observer?) protectedAttaches the provided managed object to this object.
- autoAttach(propertyName, observer?) protectedObserves a property, so that any object assigned to it is attached immediately.