Commanded v1.0.1 Commanded.Commands.CompositeRouter View Source

Composite router allows you to combine multiple router modules into a single router able to dispatch any registered command from an included child router.

One example usage is to define a router per context and then combine each context's router into a single top-level composite app router used for all command dispatching.

Example

Define a composite router module which imports the commands from each included router:

defmodule Bank.AppRouter do
  use Commanded.Commands.CompositeRouter, application: Bank.App

  router(Bank.Accounts.Router)
  router(Bank.MoneyTransfer.Router)
end

You can dispatch a command via the composite router which will be routed to the appropriate child router:

alias Bank.AppRouter

command = %OpenAccount{account_number: "ACC123", initial_balance: 1_000}

:ok = AppRouter.dispatch(command)

A composite router can include composite routers.

Link to this section Summary

Link to this section Functions

Link to this macro

router(router_module)

View Source (macro)