JBoss.orgCommunity Documentation
A container is always required to access a service, because the eXo Kernel relies on the dependency injection. This means that the lifecycle of a service (for example, instantiating, opening and closing streams, disposing) is handled by a dependency provider, such as the eXo Container, rather than the consumer. The consumer only needs a reference to an implementation of the requested service. The implementation is configured in an .xml configuration file that comes with every service. To learn more about the dependency injection, visit here.
eXo Platform provides two types of containers: RootContainer and PortalContainer.
The RootContainer holds the low level components. It is automatically started before the PortalContainer. You will rarely interact directly with the RootContainer except when you activate your own extension. The PortalContainer is created for each portal (one or several portals). All services started by this container will run as embedded in the portal. It also gives access to components of its parent RootContainer.
In your code, if you need to invoke a service of a container, you can use the ExoContainerContext helper from any location. The code below shows you a utility method that you can use to invoke any eXo Platform services.
public class ExoUtils {
/**
* Get a service from the portal container
* @param type : component type
* @return the concrete instance retrieved in the container using the type as key
*/
public <T>T getService(Class<T> type) {
return (T)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(type);
}
}
Then, invoking becomes as easy as:
OrganizationService orgService = ExoUtils.getService(OrganizationService.class)