Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Minor formatting & @ signs

...

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

...

Tapestry proceeds with this information.

Check for

...

@InjectService

Tapestry checks first for the InjectService @InjectService annotation. The value of this annotation is the service id to inject. When InjectService @InjectService is present at the point of injection, that process is done, though it can fail if the service id indicated does not exist, or if the service's interface is not compatible with the field's type.

...

This step applies only to IoC layer injection (not to injection into components).

When the Inject @Inject annotation is not present at the point of injection, Tapestry checks to see if a resource can be injected. When the Inject annotation is present, this step is skipped (this is necessary when the object to be injected has a type that conflicts with a resource type, such as List or Class).

  • 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

...

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.

...

  • If there is a single matching service, then the value to inject as been identified.
  • If there are no matches, and there were no marker annotations at the point of injection, then the Tapestry continues to the next step.
  • Otherwise there were either no matches, or too many matches: Tapestry will throw a RuntimeException.

MasterObjectProvider Lookup

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

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

...

Note

A common problem when extending injection is that contributions into the MasterObjectProvider configuration have to be handled carefully. Any dependencies of the contributed objects should be resolvable using the early stages of the injection process, otherwise MasterObjectProvider will have to be instantiated in order to handle its own injection: Tapestry will detect this impossibility and throw an exception. In addition, the TypeCoercer service is used by several ObjectProvider implementations, so the same restrictions apply to TypeCoercer service contributions.

...

Checks any contributions to the ServiceOverride service (API). 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 (API) to look for an object that can be injected.

...

@InjectService in Components

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

...