Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed bad links due to copy-paste from cwiki-test

...

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.

...

  • Check for @Value annotation
  • Check for @Symbol annotation
  • Check for a unique service in the Registry whose service interface matches the parameter type
    Usually, the @Inject annotation is supplemented by an additional annotation which triggers a specific ObjectProvider to provide the value.

@Value Annotation Provider

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);
  }

...

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.

...

An exception is thrown if there are no matches, or if there are multiple matches.

Alias Object Provider

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

Defining New Providers

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());
  }

...

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

...

 

Scrollbar