Class OsgiComponentInjector

  • All Implemented Interfaces:
    IComponentInstantiationListener

    public class OsgiComponentInjector
    extends Injector
    implements IComponentInstantiationListener
    A hook for injecting OSGi services into Wicket components. This class performs field injection for all component fields annotated by @javax.inject.Inject by looking up a service of the required type from the OSGi service registry.

    To enable this mechanism, register the injection in your Application.init() method like this:

     getComponentInstantiationListeners().add(new OsgiComponentInjector());
     
    By default, injected services are wrapped in a proxy to take care of class loading issues when deserializing a component from the page store. On serialization, the proxy replaces the wrapped service (which may not be serializable itself) by a serializable reference (its interface name, essentially). On deserialization, the proxy retrieves the matching service from the OSGi service registry.

    TODO Injection is not deterministic when there is more than one service of the required type. This class should be extended to disambiguate candidate services either by a @Named qualifier or by a dedicated qualifier taking service properties as parameters.

    Author:
    Harald Wellmann