The reference to a bean injected into an injection point, or obtained by programmatic lookup, is usually not a direct reference to an instance of a bean, unless the injected bean is of @Dependent
scope.
Instead of the actual bean instance, Weld injects a client proxy that is responsible for ensuring only the bean instance associated with the current context has a method invoked on it. That might sound confusing, but it will become clearer with an example.
@RequestScoped public class RequestBean { ... } @ApplicationScoped public class ApplicationBean { @Inject RequestBean bean; }
Given the two beans we just defined, we would not want the same @RequestScoped
bean to be used by all requests to our application, as there is only one instance of the @ApplicationScoped
bean. The client proxy is injected into the @ApplicationScoped
bean instead of an instance of the @RequestScoped
bean and is responsible for retrieving the bean instance from the current request scope whenever...