Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • A field in a component class, autobuilt object, or service implementation class the @Inject annotationis annotated with @Inject.
  • A method parameter to a service builder method, a decorator method, or a contribute method (in a Tapestry IoC module class).
  • A constructor parameter to an autobuilt object, or a service implementation class.
  • Any of the above with an @InjectService @InjectService annotation.

These define the point of injection.

Injection also covers a related matter: providing special resources to a service or component. For a service, the service's id (as a string) or extensible configuration (as a Collection, List or Map) may be provided. For a component, the component's id, locale, message catalog, or component resources may be provided.

...

This section describes standard injection, which applies at the IoC layer: autobuild autobuilt objects and service implementations. The steps for injection into Tapestry components are slightly different and are covered later.

...

  • org.slf4j.Logger – The Logger of the service being constructed (or the logger of the Module class being instantiated).
  • ObjectLocator – For contribute methods, used to locate additional objects.
  • ServiceResources – For service builder methods, an extended version of ObjectLocator. Class The service interface type.
  • OperationTracker – Used to track deeply nested operations so that errors can be reported sensibly.
  • Object, or service interface type – Passed to decorator methods.
  • Collection, List, Map – Assembled service configurations passed to service builder methods (or service class constructors).
  • Configuration, OrderedConfiguration, MappedConfiguration – Configuration passed to contribute methods, to build service configurations.

    If field type does not match any of the available resource types, or the Inject annotation is present, logic continues to the next step.

    Warning

    Injection of resources into fields is triggered by the presence of the @InjectResource annotation, whereas injection of resources into parameters occurs when the Inject or InjectService annotation is not present. These rules are slightly tricky, which reflects a desire to avoid any annotations except when needed, and the fact that field injection came much later than parameter injection.

...

Often this is used to perform additional setup, such as registerring a service as a listener of events produced by another service:

Code Block

public class MyServiceImpl implements MyService, UpdateListener
{
  @PostInjection
  public void registerAsListener(UpdateListenerHub hub)
  {
    hub.addUpdateListener(this);
  }
}

...