Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Renamed (again)
Wiki Markup
{scrollbar}

Tapestry IoC Decorators

Decoration has been replaced, in Tapestry 5.1, with advice, which is a simpler mechanism for accomplishing the same thing.

...

Decorations are driven by service decoration methods. Often, a reusable service exists to do the grunt work of creating and instantiating a new class.

Service Decoration Methods

Code Block
java
java
package org.example.myapp.services;

import org.apache.tapestry5.ioc.services.LoggingDecorator;
import org.slf4j.Logger;

public class MyAppModule
{
  public static Indexer build()
  {
    return new IndexerImpl();
  }
  
  public static <T> T decorateIndexer(Class<T> serviceInterface, T delegate, 
    String serviceId, Logger logger,
    
    LoggingDecorator decorator)
  {
    return decorator.build(serviceInterface, delegate, serviceId, logger);
  } 
}

...

But as we'll see, its possible to have a single decorator method work on many different services by using annotations.

Targetting Multiple Services

By using the @Match annnotation, you may identify which services are to be decorated.

...

Note: Another idea will be other ways of matching services: base on inheritance of the service interface and/or based on the presence of particular class annotations on the service interface. None of this has been implemented yet, and can readily be accompllished inside the decorator method (which will return null if it decides the service doesn't need decoration).

Ordering of Decorators

In cases where multiple decorators will apply to a single service, you can control the order in which decorators are applied using an additional annotation: @Order.

This annotation allows any number of ordering constraints to be specified for the decorator, to order it relative to any other decorators.

...

It should now be evident that the delegate passed into a decorator method is sometimes the core service implementation, and some times an interceptor object created by some other decorator method.

Creating your own Decorators

Decorators are a limited form of Aspect Oriented Programming, so we have borrowed some of that terminology here.

...