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.