Sunday, July 27, 2008

@Marker annotation of tapestry5

Used to define one or more marker annotations for a service implementation. This allows for injection based on the combination of type and marker interface. These marker interfaces should not have any values. The mere presence of the marker annotation is all that is needed.

Tapestry defines two such services, in the TapestryModule.

public AssetFactory buildClasspathAssetFactory(ResourceCache resourceCache,

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


return factory;

public AssetFactory buildContextAssetFactory(ApplicationGlobals globals)
return new ContextAssetFactory(request, globals.getContext());

Here's an example, you can see how Tapestry is figuring out which service to inject based on the presence of those annotations:

public void contributeAssetSource(MappedConfiguration configuration,
AssetFactory contextAssetFactory,

AssetFactory classpathAssetFactory)
configuration.add("context", contextAssetFactory);
configuration.add("classpath", classpathAssetFactory);


No comments :