Oracle GlassFish Server 3.0.1 Add-On Component Development Guide

Instantiation Cascading in HK2

Injection of instances that have not been already instantiated triggers more instantiation. You can see this as a component instantiation cascade where some code requests for a high-level service will, by using the @Inject annotation, require more injection and instantiation of lower level services. This cascading feature keeps the implementation as private as possible while relying on interfaces and the separation of contracts and providers.

Example 2–2 Example of Instantiation Cascading

The following example shows how the instantiation of DeploymentService as a Startup contract implementation will trigger the instantiation of the ConfigService.

public interface Startup {...}
Iterable<Startup> startups;
startups = componentMgr.getComponents(Startup.class);
public class DeploymentService implements Startup {
	ConfigService config;
public Class ConfigService implements ... {...}