Niclas Hedhman wrote:
> I think this is the more common case, but that it is not out of the
> question to have new instances as well. And as discussed off-list just
> now, your suggestion with passing in an ObjectBuilder/CompositeBuilder
> that is handed down the graph from the top, one can easily provide for
> "new instance" if needed.
> I think a bigger example would show how good/bad this would end up in
> reality, and final opinion is to be formed from experimentation... ;-)

The explicit usecase I have is wiring of Views, Models and Controllers 
in my Swing app. The views have:
public MyView(@Uses MyModel model, @Uses SubView subView)
{
setModel(model);
add(subView, BorderLayout.NORTH);
..
}
controllers have:
public MyController(@Uses MyModel model, @Uses MyView view)
{
..
}

With the current behaviour I had to do all of the above as @Services, to 
get the instance reuse. But that is kind of bizarre, especially since I 
then cannot instantiate two MyViews!

With the @Uses instance-reuse in place I can use @Uses for all 
injections, and so then I can create an entirely wired view just by 
instantiating the root object. Everything else will just ripple-create 
from there, but with shared instances where necessary. To create a new 
UI instance I just do the same thing again, and I get a new UI which is 
totally separate from the first one.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to