How to retrieve/inject the value of a single parameter from the YAML config file

14 views
Skip to first unread message

Vadim Oglinda

unread,
Sep 4, 2020, 3:17:27 AM9/4/20
to Bootique User Group
I can't figure out what is the mechanism to retrieve / inject the value of a single root level parameter from the config yml file without using the ConfigurationFactory.
say the only thing in the config file is just:
param1: value1

I want to use value1 within a @Provides method to construct an object.

Thanks.

Andrus Adamchik

unread,
Sep 5, 2020, 2:02:11 AM9/5/20
to Bootique User Group
Hi Vadim,

Bootique somewhat intentionally doesn't provide explicit API for property access, steering the user towards writing factory objects. Though, as you said, in some cases this may be a valuable shortcut. And you can do with the existing methods. You'd still need a ConfigurationFactory though, as this is the object that stores the configuration tree. So it is the source of this data. And then you can retrieve the value as e.g. a String, using "param1" as a root prefix:


@Provides
@Singleton
MyService provideMyService(ConfigurationFactory cf) {
String value = cf.config(String.class, "param1");
...
}

HTH,
Andrus

unv...@gmail.com

unread,
Sep 7, 2020, 8:31:01 AM9/7/20
to Bootique User Group
that did the trick. thanks.
Reply all
Reply to author
Forward
0 new messages