Although I have not tried this exact situation , beans are usually not re-injected in CDI. Instead, a proxy server that knows about its context is entered.
Using this mechanism, you can inject, say, a bean session area in a bean application area. Each application user with a bean scope goes to the same bean and the same proxy, but the proxy server then dynamically resolves calls with it to a different bean for each user.
So, although the @Stateless scope is basically a "application", it is possible that the proxy representing User in your `SomeBackendService 'is still delegating the correct scope version.
ps
If with layers you really mean modules, as in web modules and EJB modules that are part of the EAR, this will be a bit more complicated, since CDI does not always work as expected between modules (especially in JBoss AS). this is due to the ambiguity that the βapplicationβ and, therefore, the scope is within the EAR.
Arjan tijms
source share