Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: cleanups

...

Injection also covers a related matter: providing special resources to a service or component (remember that pages are specialized components). 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 checks first for the @InjectService annotation. The value of this annotation is the service id to inject. When @InjectService is present at the point of injection, that process the search is donecomplete, though it the injection can fail (throwing an exception) if the service id indicated does not exist, or if the service's interface is not compatible with the field's type.

...

When the @Inject annotation is not present at the point of injection, Tapestry checks to see if a resource can be injected. Services are global values, but resources are specific to the service under construction.

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

...

Tapestry then works through the known marker annotations. For each marker annotation that is present at the point of annotationinjection, Tapestry eliminates services which do not have the marker. Thus, if multiple marker annotations are present, the final service must have all of them.

...

  • If there is a single matching service, then the value service 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.

...

This is the point at which Tapestry's extensibility comes into play. MasterObjectProvider is a service, with a configuration of ObjectProviders (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 only 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 for the presence of the @Value annotation. If present, then the annotations annotation's value is evaluated (to expand any symbol references), and the TypeCoercer coverts service is used to convert the resulting String to the injection type (the field or parameter type).

Symbol ObjectProvider

Similar to the Value ObjectProvider: the @Symbol annotation's value (if present) is lookup up and looked up using the SymbolSource service, and converted to the injection type via the TypeCoercer service.

Autobuild ObjectProvider

...

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.

...

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.

...

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

Further injections may take place using the parameters of the methodThe method often takes no parameters; however if the method has parameters, these parameters are new points of injection.

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

...

You may use the @InjectService annotation on component fields.

...