Posts

Showing posts with the label Multiple Component mapping to one Service

Control Dependency Injection in OSGI at Runtime (Binding/Resolving the Component to a Service at Runtime)

Image
  Use Case:   As per regular pattern we bind a service interface for service implementation but there might be certain use cases for which we need to bind Service Interface to a Specific Implementation Class at run time as shown below.  This can be achieved using any of the following three methods depending upon our use case.   Options: 1)    Default mapping via Service ID By Default System will do the mapping to Service ID which is created First. In the above example since the Service Impl A is created First so it binds to A(Whose service ID is 8378 in this case when compared to service id for Impl B which is 8380). Refer below for Binding by Service ID.   2)    Mapping using Service Ranking In this option we can set specific service Ranking for each of the component implementing the service as shown below.In this case component implementation which has highest(Largest number) rank gets invoked.   Example: //Option 2 Binding by using Service Ranking w