liveBook · Manning

Handler registry

As explained in Clean Applications with Hexagonal Architecture

A mapping from operation types or other keys to the handlers responsible for processing them.

When adapters inject individual use cases, adding handlers can spread wiring changes across the application. A handler registry centralizes routing: adapters send commands or queries through a bus, which resolves each message type to its handler. The registry belongs to bus assembly infrastructure, not the application core. section 4.5.1 section 6.2.3

A typical registry-based dispatch works as follows:

  • At startup, discover handler beans and index them by the message types they accept. section 6.2.3
  • At runtime, have the bus look up the incoming message type and delegate to its handler, without rescanning the application context. section 6.2.3
  • Fail fast when a command has no registered handler; adding a handler should not require adapter changes or manual routing. section 4.5.1

Typed handler routing

A registry can map PublishArticleCommand to PublishArticleHandler by inspecting the handler bean’s generic type. A new typed handler can then join the routing table when the application context starts. section 9.6.3

Listing 9.35 CommandQueryBusAssembler: The bus beans and their registries
@Configuration
class CommandQueryBusAssembler {
 
  @Bean
  public CommandBus commandBus(
    final ApplicationContext applicationContext) {
    return new SpringCommandBus(
      new com.emedina.command.spring
        .Registry(applicationContext));
  }
 
  @Bean
  public QueryBus queryBus(
    final ApplicationContext applicationContext) {
    return new SpringQueryBus(
      new com.emedina.query.spring
        .Registry(applicationContext));
  }
}

The assembler listing shows command and query buses constructed with registries backed by the application context. section 9.6.3

How Clean Applications with Hexagonal Architecture covers it

How deep it goes
Builds the runtime index from typed handler beans and explains lookup, while keeping the registry in assembly infrastructure.
Examples
Maps PublishArticleCommand to PublishArticleHandler and mirrors the registry approach for queries.
What it assumes
Assumes typed handler interfaces and Spring-discovered handler beans for building the runtime index.
What you can do after
Configure Spring bus infrastructure to resolve typed command and query handlers without manual routing.
How it connects
Connects command buses, query buses, typed handlers, Spring beans, and the application context.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clean Applications with Hexagonal Architecture. The section links point to the parts of the book it draws on.