RoutingService
Provides the ability to return (and therefore have rendered) an alternative object from an action invocation.
Primary use case: if an action returns an aggregate leaf (that is, a child object which has an owning parent), then the parent object can be returned instead.
For example, an action returning OrderItem might instead render the owning Order object. It is the responsibility of the implementation to figure out what the "owning" object might be.
API
interface RoutingService {
boolean canRoute(Object original) (1)
Object route(Object original) (2)
}
| 1 | canRoute(Object)
whether this implementation recognizes and can "route" the object. |
| 2 | route(Object)
The object to route to instead; this may be the same as the original object, some other object, or (indeed) |
Implementation
The Core Runtime Services module
provides a default implementation of this service, refguide:core:index/runtimeservices/routing/RoutingServiceDefault.adoc.
This implementation will always return the original object provided, or redirect to the home page if a null or void was provided.
Under the covers this implementation uses the HomePageResolverService.
Usage
Unlike most other domain services, the framework will check all available implementations of RoutingService to return a route, rather than the first implementation found; in other words it uses the chain-of-responsibility pattern.
Services are called in the order defined by the @jakarta.annotation.Priority annotation.
The route used will be the result of the first implementation checked that declares that it can provide a route.