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

Mark Struberg struberg at yahoo.de
Wed Apr 4 13:39:52 EDT 2018


you could look at Apache DeltaSpike @Configuration and he whole DS config mechanism.
http://deltaspike.apache.org/documentation/configuration.html
It's battle proven and also the origin of microprofile-config and JSR-382.Runs on anything EE6 ++, from Java7 to Java10
LieGrue,strub
 

    On Tuesday, 3 April 2018, 10:25:38 CEST, Matej Novotny <manovotn at redhat.com> wrote:  
 
 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
_______________________________________________
weld-dev mailing list
weld-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/weld-dev
  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20180404/fc90fedf/attachment.html 


More information about the weld-dev mailing list