bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

new feature - search packages for objects to instantiate #253

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Spring supports this with @Component/@Service annotations as does Stripes and 
it can be quite 
handy. 

Basically in a module it'd be handy to just declare the packages to scan for 
classes which are 
annotated with some annotation (say @Service) and they'll be automatically 
added to the module 
binder without the developer having to edit the code for the module every time 
a new service is 
created. i.e. service objects can declare themselves as being bindable by using 
an annotation and 
being in the right package.

Admittedly, this isn't that hard for an end user to create for themselves; but 
I figured it'd be a 
handy feature to include out of the box.

Original issue reported on code.google.com by james.st...@gmail.com on 30 Sep 2008 at 11:33

GoogleCodeExporter commented 9 years ago
To clarify what you probably meant, I put up a small comparison a while ago: 
http://code.google.com/p/garbagecollected/wiki/GuicySpring

You can pretty much already do that with @ImplementedBy, @ProvidedBy and scope 
annotations, without classpath scanning. What you can't do in 1.0 using these 
mechanisms:
- binding annotations
- scope annotations on the interface that has @ProvidedBy, @ImplementedBy (only 
on 
the impl), I think this has been fixed in 2.0.
- failing early (these are JIT bindings, with classpath scanning you'd generate 
explicit bindings, I suppose)

I think Spring 2.5's self-annotated beans are plain ugly, and that we shouldn't 
have 
had @ProvidedBy and @ImplementedBy in the first place. Guice should stay away 
from it 
as far as possible. 

So as you mentioned, this could be an extension to Guice which you could offer 
as a 
separate download. And maybe we should even remove @ImplementedBy, @ProvidedBy 
from a 
future Guice version...

Original comment by robbie.v...@gmail.com on 30 Sep 2008 at 2:09

GoogleCodeExporter commented 9 years ago
Just-in-time bindings can solve part of this.

The other part would be to write a custom Module that take a Package and 
creates appropriate bindings for this. 
This would be a Guice extension -- we're not interested in including additional 
autoconfiguration.

Original comment by limpbizkit on 2 Nov 2008 at 9:23