1.2. What is a ServiceRegistry
?
A ServiceRegistry
, at its most basic, hosts and manages Services. Its contract is defined by the org.hibernate.service.ServiceRegistry
interface.
We already gave a basic overview and definition of services. But services have other interesting characteristics as well:
Services have a lifecycle.
They have a scope.
Services might depend on other services.
They need to be produced (choose using one implementation over another).
The ServiceRegistry
fulfills all these needs.
In a concise definition, the ServiceRegistry
acts as a Inversion-of-control (IoC) container.
Why not just use an existing IoC framework? The main reason was that this had to be as light-weight and as small of a footprint as possible. The initial design also had called for Services
to be swappable at runtime, which unfortunately had to be removed due to performance problems in the proxy-based swapping-solution; the plan is to investigate alternate ways to achieve swap-ability with better performance at a later date.
A Service
is associated with a ServiceRegistry
. The ServiceRegistry
scopes the Service
. The ServiceRegistry
manages the lifecycle of the Service
. The ServiceRegistry
handles injecting dependencies into the Service
(actually both a pull and a push/injection approach are supported). ServiceRegistries
are also hierarchical, meaning a ServiceRegistry
can have a parent ServiceRegistry
. Services in one registry can depend on and utilize services in that same registry as well as any parent registries.