Versions Compared

Key

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

Scrollbar

When you don't provide the @InjectService annotation on a parameter (to a service builder method or constructor), Tapestry will resolve the parameter automatically.

...

If this sounds vague, its because there is not just one ObjectProvider; there's a whole set of them, forming a chain of command. The commands in the chain may provide an object based on the parameter type, or based on additional annotations on the parameter.

...

The Value annotation allows a literal value to be injected. When combined with symbols, they represent a way for parts of the overall service network to be spot-configured. For example:

Code Block
java
java
  public MyService build(@Value("${max-seconds}") long maxSeconds)
  {
    return new MyServiceImpl(maxSeconds);
  }

Here, the MyService service requires a configuration of a number of seconds. The value is supplied as a symbol, with a factory default that may be overwritten with an application default.

Usually, the symbol reference is only part of the string, i.e. @Value("${report.dir}/${report.name}.txt")

@Symbol Annotation Provider

This is closely related to the @Value annotation approach, except that the annotation directly specifies a symbol name.

Code Block
java
java
  public MyService build(@Symbol("max-seconds") long maxSeconds)
  {
    return new MyServiceImpl(maxSeconds);
  }

Service Provider

This is always that last object provider checked.

...

The tapestry-core module defines the Alias object provider, which is used as a way to override services or disambiguate services (when multiple services implement the same interface).

...

New providers can be specified by contributing to the MasterObjectProvider service's configuration. The configuration is mapped, with the keys being the provider prefix, and the values being the object provider implementation.

Example:

Code Block
java
java
  public void contributeMasterObjectProvider(OrderedConfiguration<ObjectProvider> configuration)
  {
    configuration.add("MyObject", new MyObjectProvider());
  }

This establishes a name for the object provider (useful if the exact order of execution of the provider, relative to other providers, is relevant).

Of course, this is a simplified example. In a real scenario, the provider is most likely a service with its own dependencies.

 

Scrollbar