How about a Module that iterates over the directory containing the
properties file, and binds a Properties instance with Names.named() based on
the filename?
Then you could do @Inject @Named("MyWindow") Properties props.

Less than ideal because the @Named("MyWindow") in a class called MyWindow is
a little repetitive, but not terrible.


2009/9/21 Olivier Grégoire <[email protected]>

> Any idea?
>
> I know my previous response was during week-end. Maybe some people skip
> their mail during w-e.
>
>
> Olivier
>
> Le 19 septembre 2009 09:54, Olivier Grégoire <[email protected]> a écrit
> :
>
>> In this case, we would only be moving the problem, since I have about one
>> properties file per class. I would still have to know the class name at
>> injection time to load the right properties file. Making one annotation per
>> class that needs injection would of course be redundant (but a temporary
>> possible solution) .
>>
>> Is there a way to use the SPI so that I know when a class needs to
>> register its own type (or class name) to its dependencies?
>>
>>
>> Olivier
>>
>>
>> 2009/9/19 Dhanji R. Prasanna <[email protected]>
>>
>> Why not simply inject the properties directly? Using an annotation and a
>>> Map<String, String>
>>> Dhanji.
>>>
>>> 2009/9/19 Olivier Grégoire <[email protected]>
>>>
>>>
>>>> Dears,
>>>>
>>>>
>>>> I'm developing a small Swing application that needs at some points
>>>> JMenuBars. A sample describes more than words:
>>>>
>>>> public class MyWindow extends JFrame {
>>>>  public MyWindow (@Menu("myBar") JMenuBar myBar, @Menu("secondBar")
>>>> JMenuBar secondBar) { ... }
>>>> }
>>>>
>>>> class MenuBarFactory {
>>>>  public JMenuBar createMenuBar(Class<?> forType, String menuName) {
>>>>    // Fetch resources from properties file linked to forType
>>>>    //   in this case MyWindow.class
>>>>    // build menuBar for the menuName
>>>>    // return menuBar
>>>>  }
>>>> }
>>>>
>>>>
>>>> My problem is that I would like to pass automatically two parameters to
>>>> the factory: the forType and the menuName.
>>>>
>>>> I've well thought about injecting the factory, but I'm not very
>>>> convinced because "myBar" and "secondBar" are configuration strings and
>>>> should rather be present in the annotation (instead of in the code), and
>>>> also because the forType will always be the class of the injectee which
>>>> is something already known from Guice.
>>>>
>>>> Is there a way to do this using the SPI, for instance?
>>>>
>>>>
>>>> Regards,
>>>>
>>>> Olivier
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to