Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Wiki Markup
{scrollbar}
The starting point for Tapestry IOC services and injection is knowing a few conventions: what to name your classes, what packages to put them in and so forth.

...

The PropertyAccess service is defined inside TapestryIOCModule's bind() method:

Code Block

  public static void bind(ServiceBinder binder)
  {
    . . .
    binder.bind(PropertyAccess.class, PropertyAccessImpl.class);
    binder.bind(ExceptionAnalyzer.class, ExceptionAnalyzerImpl.class);
    . . .
  }

This example includes ExceptionAnalyzer, because it has a dependency on PropertyAccess:

Code Block

public class ExceptionAnalyzerImpl implements ExceptionAnalyzer
{
    private final PropertyAccess propertyAccess;
    public ExceptionAnalyzerImpl(PropertyAccess propertyAccess)
    {
        this.propertyAccess = propertyAccess;
    }

    . . .
}

...

Tapestry defines two such services, in the TapestryModule.

Code Block

  @Marker(ClasspathProvider.class)
  public AssetFactory buildClasspathAssetFactory(ResourceCache resourceCache,

  ClasspathAssetAliasManager aliasManager)
  {
    ClasspathAssetFactory factory = new ClasspathAssetFactory(resourceCache, aliasManager);

    resourceCache.addInvalidationListener(factory);

    return factory;
  }

  @Marker(ContextProvider.class)
  public AssetFactory buildContextAssetFactory(ApplicationGlobals globals)
  {
    return new ContextAssetFactory(request, globals.getContext());
  }

...

Here's an example. Again, we've jumped the gun with this service contributor method (we'll get into the why and how of these later), but you can see how Tapestry is figuring out which service to inject based on the presence of those annotations:

Code Block

  public void contributeAssetSource(MappedConfiguration<String, AssetFactory> configuration,
      @ContextProvider
      AssetFactory contextAssetFactory,

      @ClasspathProvider
      AssetFactory classpathAssetFactory)
  {
    configuration.add("context", contextAssetFactory);
    configuration.add("classpath", classpathAssetFactory);
  }

This is far from the final word on injection and disambiguation; we'll be coming back to this concept repeatedly. And in later chapters of the cookbook, we'll also go into more detail about the many other concepts present in this example. The important part is that Tapestry primarily works off the parameter type (at the point of injection), but when that is insufficient (you'll know ... there will be an error) you can provide additional information, in the form of annotations, to straighten things out.

Wiki Markup
{scrollbar}