Following some principles that say that software (especially business logic) should be "framework independent", I would like to know if it is possible to apply some wrapper / adapter in libraries that are based on Annotations?
We can take as an example, in Java the OSGi Declarative Services (DS) Annotations framewor, which uses annotations to create "Components" and use, and abuse Dependency Injection.
@Component(name = "Example", scope = ServiceScope.SINGLETON, service = ExampleSomething.class, immediate = true)
class Example implements ExampleSomething {
@Override
public void doSomething() {
}
}
interface ExampleSomething {
void doSomething();
}
@Component(name = "ExampleRef", scope = ServiceScope.SINGLETON, service = ExampleSomethingToRef.class, immediate = true)
class ExampleRef implements ExampleSomethingToRef {
@Reference
ExampleSomething exampleSomething;
@Activate
void onInit(Map<String, Object> properties) {
}
@Override
public void makeSomething() {
}
}
interface ExampleSomethingToRef {
void makeSomething();
}
You can use a FindHook
to hide the service you want to wrap and publish instead the wrapper with the same properties/interfaces as the underlying service.
IIRC, the OSGI Spec describes this scenario : https://docs.osgi.org/specification/osgi.core/7.0.0/framework.servicehooks.html#d0e45668