google-code-export / google-guice

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

annotate @SessionScoped and @RequestScoped with @Inherited and @Documented #135

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
it's better to annotate @SessionScoped and @RequestScoped with @Inherited
and @Documented

Original issue reported on code.google.com by isd...@gmail.com on 1 Aug 2007 at 1:44

GoogleCodeExporter commented 9 years ago
Is is?  Why?

Original comment by bslesinsky on 1 Aug 2007 at 3:37

GoogleCodeExporter commented 9 years ago
annotations on a class should be treated as contracts. when we look at this 
code:

@RequestScoped
public abstract class BaseService

we know every BaseService instance is in request scope. since every BaseService
subclass instance is a BaseService instance, so it should be in request scope 
too.

currently Guice only search annotations on a class itself, so making the 
annotation
@Inherited could simply obey the contract.

Original comment by isd...@gmail.com on 2 Aug 2007 at 3:17

GoogleCodeExporter commented 9 years ago
I'm not sure that a scope is a fixed part of a class's contract.  It seems to 
be more
a property of how the Song is used, which depends on the module.  For example, 
if a
Song depends on a SongId that comes from a request, then it should be request 
scope.
 But another Song could depend on a SongId that comes from a configuration file and
be singleton scope.  

Also, I haven't confirmed it, but I think a scope annotation is only a default. 
 For
example, a class might be declared @Singleton, but a module that binds the class
could override this with a different scope.

Original comment by bslesinsky on 2 Aug 2007 at 5:45

GoogleCodeExporter commented 9 years ago
I think @Singleton should also be @Inherited and @Documented.
a subclass could be declared such as @DefaultScope to override @Singleton,
@RequestScoped or any scope annotations inherited from super class.

Original comment by isd...@gmail.com on 2 Aug 2007 at 12:54

GoogleCodeExporter commented 9 years ago
I think that would make code harder to read.  Currently, when reading any 
class, if
no scope is declared then it's always default scope.  With inheritance, you 
need to
look at all its superclasses to find out which scope it is, and that's a more
complicated rule.

Original comment by bslesinsky on 2 Aug 2007 at 5:03

GoogleCodeExporter commented 9 years ago
This is a reasonable idea, but I think we've missed our opportunity to make 
this change. Inheriting annotations 
will break compatibility with Guice 1.0.

Original comment by limpbizkit on 5 Jun 2008 at 7:44