Which bundle is it?

This is exactly the role of the getMyFactory method: to retrieve 
information from the configuration by the bundle.

If you designed the bundle yourself and need more information that what is 
in MyFactory, then either extend MyFactory to contain the desired 
information, or add extra method next to getMyFactory in order to retrieve 
the information you want (and the bundle will exploit this method, like it 
does currently with getMyFactory) to retrieve the information in its run 
method.

Le jeudi 3 novembre 2016 16:10:06 UTC+1, Matt Duggan a écrit :
>
> Hi, 
>
> I've got a bundle that I'm adding via the initialize method of my 
> Application. 
>
> The bundle needs some configuration passed to its constructor so that it 
> can be used later on. I'd like to get this configuration from my YAML file; 
> making use of environment variable substitution if needed. So the call 
> would be ideally be something like this:-
>
> public void initialize(Bootstrap<MyConfig> bootstrap) {
>
>                 MyConfig config = <get config>;
>
> bootstrap.addBundle(new MyBundle<MyConfig>(*config*) {
>
> @Override
>
> public MyFactory getMyFactory(MyConfig config) {
>
> return config.getMyFactory();
>
> }
>
> });
>
> }
>
> However, I've not been able to figure out how to access the configuration 
> object within the bootstrap method. I've taken a look at dropwizard's own 
> code and from what I can tell, this is the nearest I can find to being able 
> to automatically grab the config. If that's right, the issue then is how to 
> grab the namespace with the right path?  Is there a way of getting the name 
> and path of the configuration file specified at runtime?
>
> MyConfig config = parseConfiguration(bootstrap
> .getConfigurationFactoryFactory(),
>
>                 bootstrap.getConfigurationSourceProvider(),
>
>                 bootstrap.getValidatorFactory().getValidator(),
>
>                 namespace.getString("file"),
>
>                 getConfigurationClass(),
>
>                 bootstrap.getObjectMapper());
>
> I could always pull in the environment variables I need directly but I'd 
> really like to make use of the config class I've got and so any guidance 
> would be very appreciated. 
> thanks
> Matt
>

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to