Can Guice be used to build flexible / variable object graphs?

2008-12-20 Thread Luis
Sorry if I am asking something too basic but I am totally new to Guice. What stops me for thinking that this is a great framework is that all the examples I have seen use objects with a very fixed and predefined object graphs. For example object A always contains objects B and C, and so forth. Bu

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-22 Thread Brian Pontarelli
There are patterns you can use to achieve this in Guice. I would warn you that using the method you describe above puts a lot of faith into the framework for constructing your UI exactly how you want. You might be better off using a factory or a builder to construct the UI. Then you can ha

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-22 Thread Brian Slesinsky
The easiest way would be to create an application-specific classes that wraps each kind of window in your application: class MyNameDialog ( private final Window window; @Inject MyNameDialog(Provider windowSource, Provider labelSource, P

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Luis
Thank you Brian and Brian (what a coincidence, I got two replies from two different Brians). The GUI example was just that, an example... and maybe not the best one. Here is another one: Let's say I want to build a menu composed of menu items and submenus. Each menu item has a label and an assoc

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Dhanji R. Prasanna
On Tue, Dec 23, 2008 at 7:22 PM, Luis wrote: > > Thank you Brian and Brian (what a coincidence, I got two replies from > two different Brians). > > The GUI example was just that, an example... and maybe not the best > one. Here is another one: > > Let's say I want to build a menu composed of menu

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Luis
Dhanji, when you say: "I would go so far as to say it's an abuse to ask the dependency injector to build your GUI for you. " I agree... it was a bad example. But again I am sure there are other cases where this makes more sense. >From the "philosophic" point of view I think the answer is now cl

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Witold Szczerba
2008/12/23 Luis : > From the "philosophic" point of view I think the answer is now clear > to me. But I am still not sure about how does Guice handle this kind > of situations: > > class MenuTree extends MenuElement { > @Inject List items; > } > There are many ways, you can do it like this: Imp

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Andrew Clegg
You can do this by binding List references annotated with a particular marker annotation to a specific implementation of List, which preloads itself with the required elements. e.g. Set up annotations called @FileMenu, @EditMenu ... and Guice can look for these and bind to the right preload

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Luis
Aha, I think I get it: the way to build an arbitrary structure is through an instance-specific provider that manually builds the given object graph. It's the same as building it by hand, but at least the code is in a separate place, and that is the point. (And the example about your MainMenuProvi

Re: Can Guice be used to build flexible / variable object graphs?

2008-12-23 Thread Dhanji R. Prasanna
or you can use the multibinder extension, that allows you to contribute bindings to a collection from various modules. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "google-guice" group. To post to this group, send