[cdi-dev] [JBoss JIRA] (CDI-622) External post-configuration of a bean

Martin Kouba (JIRA) issues at jboss.org
Mon Jul 4 14:57:00 EDT 2016

    [ https://issues.jboss.org/browse/CDI-622?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13261578#comment-13261578 ] 

Martin Kouba commented on CDI-622:

Why not use events/observers and {{@PostConstruct}}? The framework developer may even use some special "configuration holder" as a payload so that the final instance does not leak.

> External post-configuration of a bean
> -------------------------------------
>                 Key: CDI-622
>                 URL: https://issues.jboss.org/browse/CDI-622
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>            Reporter: John Ament
> The use case here is that a framework has provided the application developer with some bean, X.  While the framework can provide internal post construction support for this bean, the application developer has some need to set additional attributes on the bean prior to the bean being injected into its final target.
> The application developer currently has no way to do this.  To accomplish this feat, the framework developer must put the burden on the application developer to do both configuration and bootstrapping of this bean.  This is a bit of a pain point to be honest.  
> One idea I had was to introduce a {{@Configures}} annotation that could be used, similar to observers.  These methods (plural) could be called (based on priority) during the post construct phase and may exist in any managed bean. 
> {code}
> @Configures
> public void setupWebServer(WebServer webserver, Configuration configuration) {
>     webserver.setPort(configuration.getWebServerPort());
> }
> {code}
> In this case, webserver is the bean being configured, configuration is some other bean that retains the configuration data.  This should support normal qualifiers, and perhaps provide an injection point for the underlying {{InjectionTarget}}

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list