No problem, and thanks for your suggestions Victor.  I'll find a way :-)

On Friday, 4 November 2016 08:39:23 UTC, [email protected] wrote:
>
> Well if you are responsible of the code of this Bundle, I would advise you 
> to simply rewrite it correctly by initialising the fields (or maybe you 
> will even realise you don't need fields, who knows?) in the run method by 
> using the configuration retrieved with an abstract method :)
>
> If not, then you are a bit out of scope of how things work with Bundles 
> (and they are not perfect, for sure, I had problems too like this in the 
> past).
>
> Maybe someone from DW will have a better answer than mine also…
>
> Le jeudi 3 novembre 2016 21:14:39 UTC+1, Matt Duggan a écrit :
>>
>> Hi, it's a proprietary one but there's some fields set to default values 
>> that can't be re-set later as they are final and there are no mutator 
>> methods for them; just accessors. My thinking was to extend it and supply 
>> values via the constructor and override the accessor methods.  I could 
>> always re-factor it completely too  :-)
>>
>> On Thursday, 3 November 2016 15:32:10 UTC, [email protected] wrote:
>>>
>>> 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