btw point taken on the documentation...I'll keep in mind to sketch a FAQ on this.
On Mon, Aug 15, 2011 at 12:06 AM, Fred Faber <[email protected]> wrote: > short answer: go with multiple install() calls. > > you can mitigate the cost by doing this in a loop, which will allow you to > do something like create a list of {TypeLiteral, Impl} pairs and iterate > over them to make each call to install(). > > Fred > > On Sat, Aug 13, 2011 at 4:30 AM, Oleg Estekhin <[email protected]>wrote: > >> The documentation for assisted inject should be really updated with >> examples of generic factory, as this kind of question seems to appear >> every where on the internet but there are no answers =\ >> >> So far i got the following code to be working: >> >> class Node<T>{} - a base class for nodes, lets say nodes in a tree, >> where each subclass handles a particular type of content. >> >> class NodeFactory<T> { >> Node<T> createNode(T content); >> } >> >> >> The module contains the following code: >> >> install( new FactoryModuleBuilder() >> .implement( new TypeLiteral<Node<SomeContentType>>() >> {}, SomeContentTypeNodeImpl.class ) >> .build( new >> TypeLiteral<NodeFactory<SomeContentType>>() {} ) ); >> >> which allows me to inject NodeFactory<SomeContentType>. >> >> What should i do if i want to be able to inject >> NodeFactory<AnotherContentType>? >> >> Should i "install(...)" a separate FactoryModuleBuilder configured >> with AnotherContentType, or is it possible to add "implement()" to the >> code above and modify the "build()" in such a way, that a single >> "install()" will configure the NodeFactory both for SomeContentType >> and AnotherContentType? >> >> I will probably have a dozen of FooContentType's, so having a single >> "install()" with multiple "implement()" seems/feels to be better that >> having a dozen of "install()"s, each with a single "implement()", or >> should i just go for a multiple "install()"s? >> >> -- >> 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. >> >> > -- 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.
