Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Renamed so it's name makes sense as a stand-alone page, e.g. when appearing in "Related Articles" boxes
Wiki Markup
{scrollbar}

Overriding Tapestry IoC Services

Tapestry is designed to be easy to customize, and the IoC container is the key to that customizability.

...

The strategy used to determine what object gets injected is defined inside Tapestry IoC itself; thus we can take advantage of several features of the Tapestry IoC container in order to take control over specific injections.

Contributing a Service Override

In most cases, services are injected by matching just the type; there no @InjectService annotation, just a method or constructor parameter whose type matches the service's interface.

...

We can inject our overriding implementation of SomeServiceType using the special @Local annotation, which indicates that a service within the same module only should be injected (that is, services of the indicated type in other modules are ignored). Without @Local, there would be a problem because the override parameter would need to be resolved using the MasterObjectProvider and, ultimately, the ServiceOverride service; this would cause Tapestry to throw an exception indicating that ServiceOverride depends on itself. We defuse that situation by using @Local, which prevents the MasterObjectProvider service from being used to resolve the override parameter.

Decorating Services

Another option is to decorate the existing service. Perhaps you want to extend some of the behavior of the service but keep the rest.

...