[weld-dev] What is the best way to pass cofiguration to CDI bean using Weld?

Matej Novotny manovotn at redhat.com
Tue Apr 3 04:23:42 EDT 2018


Hi Alex,

Not sure if I get what you need to do, but I'll take a shot at it.
What about using @PostConstruct interceptor, in which you take the injected Application bean and use it to set internal state in SomeManagerImpl?
Same could be done directly within constructor (with @Inject annotation) or an initializer method.

E.g.

@ApplicationScoped
public class SomeManagerImpl implements SomeManager{} {

 private MyConfiguration config;

 @Inject
 Application app;

 @PostConstruct
 public void doSomeInit() {
  config = app.getConfig(); // get config from Application and appply here
 }
}

If I misunderstood your question, please correct me :)

Matej


----- Original Message -----
> From: "Alex Sviridov" <ooo_saturn7 at mail.ru>
> To: "weld-dev" <weld-dev at lists.jboss.org>
> Sent: Saturday, March 31, 2018 1:07:59 PM
> Subject: [weld-dev] What is the best way to pass cofiguration to CDI bean using Weld?
> 
> Hi all
> 
> Could anyone suggest solution for the following situation.
> Lets suppose we have:
> 
> public interface SomeManager{}
> 
> @ApplicationScoped
> public class SomeManagerImpl implements SomeManager{}
> 
> @ApplicationScoped
> public class Application {} //application entry point
> 
> In Application I need to pass configuration to SomeManagerImpl, but I don't
> want to
> add setConfiguration method to SomeManager interface. What is the best way
> to do it in Weld? Maybe I use some CDI mechanisms, or add extra classes.
> Please, help.
> 
> Best regards, Alex Sviridov
> 
> _______________________________________________
> weld-dev mailing list
> weld-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/weld-dev


More information about the weld-dev mailing list