-
1. Re: Disposing and InjectionPoint integration?
meetoblivion Dec 28, 2009 12:56 AM (in response to meetoblivion)ack, should be @Disposes not @Inject.
-
2. Re: Disposing and InjectionPoint integration?
gavin.king Dec 28, 2009 1:34 AM (in response to meetoblivion)I don't completely understand the question. What is the scope of the bean? What is init()? A @PostConstruct method? What is cleanUp()? A @PreDestroy method?
In general, you can do the same things with @PreDestroy that you can do with a @Disposes method. The only difference is that @Disposes is for @Produces methods.
-
3. Re: Disposing and InjectionPoint integration?
meetoblivion Dec 28, 2009 2:51 AM (in response to meetoblivion)In this case, I do not control SomeBean (in fact, in my particular scenario its a javax.jcr.Repository, or a javax.jcr.Session, depending on how used). Instances of it have to be created via producers rather than pure annotations. I'm attempting to use Session the same way one used to use hibernate's session on a session per request style. My goal is to have an annotation.
Long story short, I need an automated way of calling the cleanUp() method without modifying the bean. Will @Disposes dispose of all instances, or will I need to qualify each individual instance?
-
4. Re: Disposing and InjectionPoint integration?
gavin.king Dec 28, 2009 2:57 AM (in response to meetoblivion)If you want to write a single disposer method that matches all beans of a certain type, regardless of their qualifier, you should use the qualifier @Any. Just like any other injection point.
-
5. Re: Disposing and InjectionPoint integration?
meetoblivion Dec 28, 2009 3:00 AM (in response to meetoblivion)with Any, since it sounds like the dispose method should be in the same class as the producer, will it also catch instances created by producers in different classes?
-
6. Re: Disposing and InjectionPoint integration?
gavin.king Dec 28, 2009 3:12 AM (in response to meetoblivion)No, disposer methods apply to producers defined by the same bean.
-
7. Re: Disposing and InjectionPoint integration?
nickarls Dec 28, 2009 11:55 AM (in response to meetoblivion)This wasn't always the case in some of the drafts(?) Do you recall why it was changed?
-
8. Re: Disposing and InjectionPoint integration?
meetoblivion Dec 29, 2009 2:51 AM (in response to meetoblivion)So I ran into an interesting issue.
Let's say I'm disposing an object. In some cases, I will need access to the Field, or maybe InjectionPoint. Can I use InjectionPoint instead of @Disposes @Qualifier SomeBean someBean?
-
9. Re: Disposing and InjectionPoint integration?
gavin.king Dec 29, 2009 6:37 PM (in response to meetoblivion)
John Ament wrote on Dec 29, 2009 02:51:
So I ran into an interesting issue.
Let's say I'm disposing an object. In some cases, I will need access to the Field, or maybe InjectionPoint. Can I use InjectionPoint instead of @Disposes @Qualifier SomeBean someBean?Yes, it is possible to write
generic
producer/disposer method pairs, for example:class SomeClass { @Produces @Any Foo produceFoo(InjectionPoint ip) { ..... } void disposeFoo(@Disposes @Any Foo foo, InjectionPoint ip) { .... } }
Note that you cannot move the InjectionPoint injection up to SomeClass, since it would represent the injection point into which the SomeClass was injected, not the injection point into which the Foo was injected.
Please test this out, since it would not surprise me if this is not currently working in Weld. I need to add some language to the spec to make it much clearer that an InjectionPoint injected into a disposer method refers to the producer method bean and not to the declaring bean.