Hello Experience League Community,
I’m currently working with Sling Models and came across the @OsgiInjector annotation in the documentation. I am curious to understand its specific use and when it should be applied.
I am attaching the link to the documentation for reference:
Views
Replies
Total Likes
I found this old article(2022) from @Jörg_Hoh where there is a little explanation of OsgiInjector(I never used this one though)
https://cqdump.joerghoh.de/2022/11/28/sling-model-performance/
There is this cheat sheet from source code which is very useful AEM sling injector annotations which I usually use.
https://sourcedcode.com/blog/aem/aem-sling-model-injectors-annotations-cheat-sheet-reference-guide
Hi @purushottam_kr , to my understanding we avoid @inject annotation because of its unpredictable behaviour and performance overhead.
So, instead of @inject it is recommended to use the @OSGiService
@OSGiInjector is conceptually similar to @inject or @OSGiService but with additional metadata i.e. it provides more granular control over how OSGi services are injected.
@OSGiInjector(name="log")
you can provide the name so that in case it can distinguish between the two services which implements the same interface.
@OsgiInjector(filter="paths=/bin/something")
private List<Servlet> servlets;
In this case, the filter paths=/bin/something likely matches services (e.g., Servlet implementations) registered in the OSGi registry with a property paths having the value /bin/something. List<Servlet> means that all matching services are injected as a list.
Views
Replies
Total Likes
It allows you to inject also OSGI services into your Sling Models.
Views
Likes
Replies
Views
Likes
Replies