[JBoss JIRA] (CDI-473) Standardize eager initialisation of ApplicationScoped bean
by Antonin Stefanutti (JIRA)
[ https://issues.jboss.org/browse/CDI-473?page=com.atlassian.jira.plugin.sy... ]
Antonin Stefanutti updated CDI-473:
-----------------------------------
Fix Version/s: 2.0 (discussion)
> Standardize eager initialisation of ApplicationScoped bean
> ----------------------------------------------------------
>
> Key: CDI-473
> URL: https://issues.jboss.org/browse/CDI-473
> Project: CDI Specification Issues
> Issue Type: Feature Request
> Components: Contexts
> Reporter: Antonin Stefanutti
> Fix For: 2.0 (discussion)
>
>
> Given the proxying strategy documented in the CDI specification, normal scoped beans get initialize when an injected proxy reference is first called.
> While that's perfectly fine in the vast majority of use cases, that proves inconvenient when dealing with {{ApplicationScoped}} beans that capture application singletons which we want to bound to the application lifecycle with a {{postConstruct}} callback. As this callback is only called when a proxy is invoked, it is frequent to see the application developers using a CDI extension to meet that need, e.g.:
> {code}
> void forceInitialization(@Observes AfterDeploymentValidation adv, BeanManager manager) {
> for (AnnotatedType<?> type : eagerBeans)
> // Calling toString is necessary to force the initialization of normal-scoped beans
> BeanManagerHelper.getReferencesByType(manager, type.getBaseType(), AnyLiteral.INSTANCE).toString();
> }
> {code}
> There should be a concise way to declare that intent which would then be address by the CDI container, for example:
> {code}
> @ApplicationScoped(eager = true}
> class EagerApplicationScopedBean {
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba commented on CDI-590:
----------------------------------
bq. it doesn't support a lot of types
I thought a custom producer for any type [can be implemented|https://github.com/apache/deltaspike/blob/master/deltaspike/c...].
bq. Just use PropertyEditor API...
I don't know what do you mean. Probably {{java.beans.PropertyEditor}}?
bq. Tamaya has its own coercing system which wouldnt fit CDI very well...
For Tamaya I think it would be more meaningful to create a producer for {{org.apache.tamaya.Configuration}}. But I understand that it would be nice to leverage {{PropertyConverter}} and produce configuration properties directly.
Look, I'm not against this feature! I'm just trying to identify all pros and cons ;-)
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-590:
----------------------------------------
[~mkouba] deltaspike example is not really relevant there cause it doesn't support a lot of types. Just use PropertyEditor API and deltaspike producers wouldn't work anymore and that's just a trivial case. If you use tamaya, Tamaya has its own coercing system which wouldnt fit CDI very well without that feature IMO.
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba commented on CDI-590:
----------------------------------
Now I think I understand the concept. However, a type-safe approach - custom producer per type, reusing the same qualifier annotation (something similar to DeltaSpike {{ConfigProperty}}) - seems more suitable for the configuration use case. The integration with other DI frameworks is a different story...
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Matej Novotny (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Matej Novotny commented on CDI-590:
-----------------------------------
[~rmannibucau] got it now, or at least I hope so. Thanks for clarification.
It is indeed an interesting idea and certainly matches the use-case. Although leaving the type-safe check on user side (since it will be handled in producers) might yield...various results :)
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-590:
----------------------------------------
[~manovotn] configuration is a very common use case cause you often rely on a library which already does the conversion and sometimes even map a complex type. Also if you integrate with Spring, Pico, Guice, ... you need that or you have to write an extension which is not as trivial as it should. Rephrased this case handles CDI-X integration in a generic manner and in a simple way compared to have to 1. scan the X library beans (thing you can't do sometimes) 2. create a XBean 3. register bean you *suppose* you will need (you obviously miss the programmatic lookup approach).
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-590:
----------------------------------------
[~mkouba] yes. Suppose you have a configuration library or another IoC you want to integrate with for instance. In such cases you often have SuperFrameworkFactory.getBean(Type, Annotation, OtherParamLibSpecific) and you just can to call this building the parameters from the InjectionPoint. Today the only solution with CDI is to build an extension where you would just produce the bean and ensure it is not ambiguous using a qualifier.
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Matej Novotny (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Matej Novotny commented on CDI-590:
-----------------------------------
I don't really like this idea. It feels 'hacky' and it could also contradict the type-safe approach.
If I got it right, the idea is to have this producer:
{code}
@Produces
@MyProducerQualifier // this Qualifier has some annotation saying it is 'generic'
public Object create() {
// do some work and return Object
}
{code}
and then for this one producer to have the following injections:
{code}
@Inject
@MyProducerQualifier
String string;
@Inject
@MyProducerQualifier
Integer int;
{code}
Could you give a more specific use-case showing where this would make sense (or even better, be neccessary)?
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-590) Provide a way to produce any type in a producer
by Martin Kouba (JIRA)
[ https://issues.jboss.org/browse/CDI-590?page=com.atlassian.jira.plugin.sy... ]
Martin Kouba commented on CDI-590:
----------------------------------
I'm not sure I understand the use case. Do you want to declare a producer method whose set of bean types will not be derived from the return type? A more general description would be great.
> Provide a way to produce any type in a producer
> -----------------------------------------------
>
> Key: CDI-590
> URL: https://issues.jboss.org/browse/CDI-590
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Note: this is a follow up "adding generic producers to CDI 2.0?" thread on the list
> It is common to rely on a subsystem (another IoC, a coercing system, ...) to produce values. Today a producer can't say "I produce anything in a safe" manner.
> Idea would be for injection point aware producers with a qualifier to producer Object and match all types.
> It needs another flag (can be in @Qualifier or another annotation it is not really important) to say "I produce safely any type".
> I did a PoC on github: https://github.com/rmannibucau/generic-producer-cdi but think it can be a nice feature of CDI 2.0 since it would avoid users to have to dig into extensions for several simple cases (configuration, bridge to other IoC...)
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months
[JBoss JIRA] (CDI-591) Easy way to get an interceptor model
by Romain Manni-Bucau (JIRA)
[ https://issues.jboss.org/browse/CDI-591?page=com.atlassian.jira.plugin.sy... ]
Romain Manni-Bucau commented on CDI-591:
----------------------------------------
ic.getMethod() uses reflection and not the Annotated model so you can miss part of the model. createAnnotatedType() doesn't guarantee anything but is the best we can do today without requiring to write an extension which would make interceptor API super complicated compared to what is desired on the end user side.
> Easy way to get an interceptor model
> ------------------------------------
>
> Key: CDI-591
> URL: https://issues.jboss.org/browse/CDI-591
> Project: CDI Specification Issues
> Issue Type: Epic
> Reporter: Romain Manni-Bucau
>
> Since CDI 1.1 we can get the intercepted Bean<?> but we can't get the annotated type and method associated easily (= an injection). Would be great to enable it since often in an interceptor you need the binding to read some configuration (@Nonbinding) to change a bit the behavior.
> {code}
> @Inject
> @Intercepted
> AnnotatedType<?> type;
> @Inject
> @Intercepted
> AnnotatedMethod<?> method;
> {code}
> would be great
> Side note: would be better to be in the InvocationContext but not sure it is an option. Or it would need a CdiInvocationContext inheriting from InvocationContext probably.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
8 years, 9 months