org.jboss.solder.unwraps
Annotation Type Unwraps


@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Unwraps

Identifies a stateless producer method where each method invocation on the produced object will cause the annotated method to be invoked to produce the object.

A method is annotated with @Unwraps is registered with CDI as bean; whenever a method is invoked on the proxy the @Unwraps method is called, and the method invocation is forwarded to the result. This allows you to manual control the lifecycle of the object while still allowing it to be injected.

As the method is called every time a method invocation occurs, it is important that you do not perform expensive operations in this method. Normally you will want to simply expose an existing object via unwrap method:

 @SessionScoped
 class FooManager {

    private Foo foo;

    @PostConstruct
    void init() {
       // set up Foo
    }

    Foo getFoo() {
       return foo;
    }

    // Client immediately reflect any changes to Bar as a result
    // of changes to Foo
    @Unwraps
    Bar getBar() {
       return foo.getBar();
    }

 }
 

The return type of the annotated method must be proxyable (see Section 5.4.1 of the CDI specification, "Unproxyable bean types"). The method must not have a scope annotation.

Author:
Stuart Douglas, Pete Muir
See Also:
Produces



Copyright © 2011 Seam Framework. All Rights Reserved.