[
https://issues.jboss.org/browse/CDI-469?page=com.atlassian.jira.plugin.sy...
]
John Ament commented on CDI-469:
--------------------------------
Sure, suppose I have this qualifier:
{code:java}
@Qualifier
...
public @interface Converter {
@Nonbind String value();
}
{code}
I can define a producer field like so:
{code:java}
@Produces
@ApplicationScoped
@Converter("fooAtoB")
private Function<A,B> aToBConv = new AToBFunction();
{code}
If however these were lazily instantiated, or I had a map or looked up values via DB call,
I need to add a producer method. In this case, I want it to be generic and reusable,
however the instances that it returns should be proxied, scope aware (e.g. not unique for
each invocation, as is the current behaviour).
{code:java}
@Produces
@Converter
// @ApplicationScoped <-- scope is not valid here
public Function<?,?> createOrFindFunction(InjectionPoint ip) {
// work to look up the function
}
{code}
Scope isnt' valid here as the injection point could be different. What I'm
proposing is that we lift this restriction, in cases where the qualifiers are the same.
Allow nonbinding producer methods to have scopes
------------------------------------------------
Key: CDI-469
URL:
https://issues.jboss.org/browse/CDI-469
Project: CDI Specification Issues
Issue Type: Feature Request
Components: Beans, Contexts
Affects Versions: 1.2.Final
Reporter: John Ament
Currently, you cannot have a nonbinding producer method, e.g. one where the annotation is
read at runtime, with a scope. This means that repeated injections always happen. It
would be better if you could scope the nonbinding producer methods, so that the results
were bound, e.g. to a request scope, so that look ups can be done once.
The current way to avoid this is to use a holder object with the proper scope.
--
This message was sent by Atlassian JIRA
(v6.3.1#6329)