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

...

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

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.

...

First, it generates a set of services whose service interface is compatible with the injection type. This is based on assignability.

If the Local annotation is present, then services not from the module containing the service being constructed will be eliminated.

...

This is the point at which Tapestry's extensibility comes into play. MasterObjectProvider is a service, with a configuration of ObjectProviders.

The MasterObjectProvider is also the point at which Tapestry's IoC layer injection, and Tapestry's component injection, unite.

...

Checks for the presence of the Value annotation. If present, then the annotations value is evaluated (to expand any symbol references), and the TypeCoercer coverts the resulting String to the injection type.

...

Similar to the Value ObjectProvider: the Symbol annotation's value (if present) is lookup up and converted to the injection type.

Autobuild ObjectProvider

Checks to see if the Autobuild annotation is present and, if so, autobuilds the value for the parameter. Of course, the object being built will itself be configured via injection.

...

Checks any contributions to the ServiceOverride service. Contributions map a type to an object of that type. Thus, ServiceOverrides will override injections of services that are not qualified with a marker annotation.

Alias ObjectProvider (tapestry-core)

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

...

Asset ObjectProvider (tapestry-core)

Checks for the Path annotation.

If present, the annotation's value has embedded symbols expanded, and is converted into an Asset (which must exist).

...

Service ObjectProvider (tapestry-core)

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.

...

Any public method may have the PostInjection annotation.

Such methods are invoked after constructor and/or field injection. Only public methods will be invoked. Any return value is ignored.

...

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

No Formatcode
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 @Inject (or @InjectService) annotation.

Component field injection is very similar to IoC layer, but with a different set of injectable resources.

Injection is the responsibility of the InjectionProvider service, which is a chain-of-command across a number of implementations.

...

Checks if the field type is Block. If so, determines the block id to inject (either from the field name, or from an @Id annotation, if present).

Default InjectionProvider

...

  • String: the components' complete id
  • org.slf4j.Logger: Logger for the component (based on component class name)
  • Locale: locale for the containing page (page locale is immutable)
  • Messages: Component's message catalog

Asset InjectionProvider

Triggered by the Path @Path annotation: the Path value has symbols expanded, and is then converted to an Asset.

...

This is now supported; you may use the InjectService annotation on component fields.