Annotation Type Unwraps

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:

 class FooManager {

    private Foo foo;

    void init() {
       // set up Foo

    Foo getFoo() {
       return foo;

    // Client immediately reflect any changes to Bar as a result
    // of changes to Foo
    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.

Stuart Douglas, Pete Muir
See Also:

Copyright © 2011 Seam Framework. All Rights Reserved.