Hi!

I'd like to write down a general idea about scopes and their interaction which 
(after a talk with Pete) I think is 'implicitely' defined in the JSR-299 spec.

1) If I inject a bean of a 'shorter' ranged scope into a bean with a 'longer' 
ranged scope, then we have to use a proxy object.

An example: We do need a proxy if an @SessionScoped bean has an @RequestScoped 
bean as a member, because for every request, the @RequestScoped bean member is 
different to the one from the previous request.

We do _not_ need to use a proxy if the scope of the injected member bean is 
'equal' or 'longer' as the bean where it's a member of.

2.) Since the spec requires SessionScoped and ConversationScoped beans to be 
Serializable, those 2 have to be injected via proxies only.

Since JSR-299 gives anyone the possibility to write own Scopes, a simple 
hardcoded scope comparison matrix is not sufficient.
To work around this, we may introduce a simple list of metrics in our 
configuration, 1 for each known scope. Where a higher number means a longer 
lifetime of beans of a scope.

e.g.
scope.metric.RequestScoped=1
scope.metric.ConversationScoped=2
scope.metric.ApplicationScoped=3

If someone e.g. likes to introduce a WorkflowScoped (which typically is even 
longer than applications since they may be persisted into a database and last 
for years (kafkaesk indeed but possible)) it would get a metric of 4.
Another example: JSF has a 'FlashScoped' which would fit between RequestScoped 
and ConversationScoped ...

Open questions: 
a.) can there be 2 scopes which are 'equally' ?
b.) is a simple ordered (comma separated) list sufficient? 

WDYT? May we get this plugable enough?

LieGrue,
strub




Reply via email to