Class AbstractServiceAwareModule

  • All Implemented Interfaces:
    com.google.inject.Module

    public abstract class AbstractServiceAwareModule
    extends com.google.inject.AbstractModule
    Abstract Guice module with helper methods to bind services from OSGi service registry.

    Clients may extend this class, implement doConfigure(), and call the inherited methods with extended DSL, that allows to bind toService(...). Example of usage:

     public class MyModule extends AbstractServiceAwareModule
     {
         public MyModule(BundleContext context)
         {
             super(context);
         }
    
         @Override
         protected void doConfigure()
         {
             // bind plug-in internal local services
             bind(IInternalService.class).to(InternalService.class).in(Singleton.class);
             bind(IOtherInternalService.class).to(OtherInternalService.class);
    
             // bind neccessary imported OSGi services
             bind(IPublicService.class).toService();
             bind(IPublicQualifiedService.class).annotatedWith(Names.named("MdImplementation"))
                 .toService(IPublicQualifiedService.class, ServiceProperties.named("MdImplementation"));
         }
     }
     
    See Also:
    AbstractModule, ServiceProperties
    • Constructor Detail

      • AbstractServiceAwareModule

        public AbstractServiceAwareModule​(org.eclipse.core.runtime.Plugin bundle)
        Parameters:
        bundle - the parent bundle, cannot be null
      • AbstractServiceAwareModule

        public AbstractServiceAwareModule​(org.osgi.framework.BundleContext context)
        Parameters:
        context - the parent bundle context, cannot be null
    • Method Detail

      • configure

        protected void configure()
        Specified by:
        configure in class com.google.inject.AbstractModule
      • doConfigure

        protected abstract void doConfigure()
        Configures a Binder via the exposed methods.

        Clienst may use methods of AbstractModule and extra methods of AbstractServiceAwareModule DSL to bind imported OSGi services.