Skip to content

Beans

Overview

Module

Beans is the client-facing facade for looking up managed beans and platform services from code. Use it when constructor or field @Inject is not an option - for example inside a handler method that needs an IRepository, or to reach a platform service from a non-bean class.

Use Beans, not BeanProvider

Client code must use Beans for lookups. The platform-internal BeanProvider is not part of the client SDK and must not be referenced from client .java sources.

Example Usage:

java
import org.eclipse.dirigible.sdk.component.Beans;

// by type
CountryRepository countries = Beans.get(CountryRepository.class);

// by name and type
CountryController controller = Beans.get("countryController", CountryController.class);

// every bean assignable to the type
List<OrderProcessor> processors = Beans.getAll(OrderProcessor.class);

Prefer @Inject - and, for "all contributions of a type", List<T> injection - over Beans.get / Beans.getAll in classes that are themselves managed beans; reach for the facade only where injection cannot reach.

Methods

get()

Returns the single bean of the given type.

java
public static <T> T get(Class<T> type);
ParameterTypeDescription
typeClass<T>The bean type to resolve.

Returns

  • Type: T
  • Description: The bean assignable to type.

get() (by name)

Returns the bean registered under the given name, cast to the given type.

java
public static <T> T get(String name, Class<T> type);
ParameterTypeDescription
nameStringThe bean name (see @Component value()).
typeClass<T>The expected bean type.

Returns

  • Type: T
  • Description: The named bean.

getAll()

Returns every bean assignable to the given type.

java
public static <T> List<T> getAll(Class<T> type);
ParameterTypeDescription
typeClass<T>The type to match against.

Returns

  • Type: List<T>
  • Description: All beans assignable to type. Same set you would receive from List<T> injection.

See also

Released under the EPL-2.0 License.