Versions Compared

Key

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

...

The two marker annotations, Traditional and Primary, ensure that only a single service matches.

What's the difference between Inject and Environmental?

Inject is relatively general; it can be used to inject resources specific to a page or component (such as ComponentResources, Logger, or Messages), or it can inject services or other objects obtained from the Tapestry IoC container. Once the page is loaded, the values for these injections never change.

Environmental is different; it exposes a request-scoped, dynamically bound value

Footnote

Environmental was chosen as the value "comes from the environment", whatever that means. A name more evocative of its function still has not occurred to the Tapestry team!

.

  • Request scoped: different threads (processing different requests) will see different values when reading the field.
  • Dynamically bound: the value is explicitly placed into the Environment, and can be overridden at any time.

Environmentals are a form of loosely connected communication between an outer component (or even a service) and an inner component. Example: the Form
component places a FormSupport object into the environment. Other components, such as TextField, use the FormSupport when rendering to perform functions such as allocate unique control names or register client-side validations. The TextField doesn't require that the Form component be the immediate container component, or even an ancestor: a Form on one page may, indirectly, communicate with a TextField on some entirely different page. Neither component directly links to the other, the FormSupport is the conduit that connects them.

...

Footnotes Display