Commanded.Commands.CompositeRouter (Commanded v1.3.1) 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.


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

defmodule Bank.AppRouter do
  use Commanded.Commands.CompositeRouter


One or more routers or composite routers can be included in a Commanded.Application since it is also a composite router:

defmodule BankApp do
  use Commanded.Application


You can dispatch a command via the application which will then be routed to the associated child router:

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

:ok = BankApp.dispatch(command)

Or via the composite router itself, specifying the application:

:ok = Bank.AppRouter.dispatch(command, application: BankApp)

A composite router can include composite routers.

Link to this section Summary


Register a Commanded.Commands.Router module within this composite router.

Link to this section Functions

Link to this macro


View Source (macro)

Register a Commanded.Commands.Router module within this composite router.

Will allow the composite router to dispatch any commands registered by the included router module. Multiple routers can be registered.