Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Scrollbar

Injection in Tapestry IoC can be a complicated subject for a number of reasons:

  • Injection can occur in many places: on fields, and on parameters to methods and constructors of certain objects.
  • Parts of Injection are themselves defined in terms of Tapestry IoC services, many of which are extensible.
Div
stylefloat:right
titleRelated Articles
classaui-label
Content by Label
showLabelsfalse
showSpacefalse
titleRelated Articles
cqllabel = "injection" and space = currentSpace()

Despite this, injection generally Just Works: most of the time, you want Tapestry to inject a service, and only a single service implements the service interface.

...

  • 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.

Service Lookup by Type and Annotations

...

As a chain-of-command, each of the following ObjectProviders will be considered and will attempt to identify the object to be injected.

Note

...

...

Value ObjectProvider

Checks for the presence of the @Value annotation. If present, then the annotation's value is evaluated (to expand any symbol references), and the TypeCoercer service is used to convert the resulting String to the injection type (the field or parameter type).

...

Uses the Alias service (API) to look for an object that can be injected.

Warning

Deprecated in Tapestry 5.2 and removed in 5.4.

This is commonly used to override a built-in service by contributing an object with the exact same interface. This is an older and more complex version of the ServiceOverride provider.

...

Looks for the @Service annotation; if present, the annotation's value is the exact service id to inject. This is necessary because injections into component fields are always triggered by the Inject annotation.

Note

This is supported but no longer necessary, as the @InjectService annotation is now also supported for component fields.

SpringBean ObjectProvider (tapestry-spring)

...

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);
  }
}

Component Injection

Inside Tapestry components, injection occurs exclusively on fields and is always triggered by the @Inject (or @InjectService) annotation.

...

You may use the @InjectService annotation on component fields.

Scrollbar