You are looking at documentation for an older release. Not what you want? See the current release documentation.
To access a service, you need to use a Container. Let's see the Java files in https://github.com/exoplatform/kernel/tree/master/exo.kernel.container/src/main/java/org/exoplatform/container.
Among the classes you see in this directory, you only will be interested in these three container types:
RootContainer: This is a base container. This container plays an important role during startup, but you should not use it directly.
PortalContainer: This is created at the startup of the portal web application (in the init() method of the PortalController servlet).
StandaloneContainer: A context-independent eXo Container.
The StandaloneContainer
is also used for unit tests.
Using only one container
Even if there are several container types, you always use exactly one. The RootContainer is never directly used. It depends on the execution mode if you use the PortalContainer or the StandaloneContainer. You will ask how to find out the execution mode in your application and how to manage these two modes. It is easy, and you do not have to worry about it because the ExoContainerContext class provides a static method that allows you to get the right container from anywhere (see How to get the container).
PicoContainer
All containers inherit from the ExoContainer class which itself inherits from a PicoContainer
.
PicoContainer is a framework
which allows eXo to apply the IoC (Inversion of Control) principles.
The precise implementation of any service is unknown at compile time.
The various implementations can be used, eXo supplies different implementations but they also may be delivered by other vendors.
The decision of using which service during runtime is made in configuration files.
These configuration files are read by the container, the container adds all services to a list or more exactly a Java HashTable.
It is completely correct to suppose that the configuration.xml
you have already seen plays an important role.
But there are more places where a configuration for a service can be defined as you see in the next section.
In your Java code, you have to use ExoContainer myContainer = ExoContainerContext.getCurrentContainer(); to access the current container.
It does not greatly matter to your application if the current container is a PortalContainer
or a StandaloneContainer
.
Once you have your container, you may access any service registered in the container using MyService myService = (MyService) myContainer.getComponentInstance(MyService.class);.
You easily realize that MyService.class
is name of the service interface.