Ming.CompositeRouter (Ming v0.1.0)
View SourceComposite 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.Router do
use Ming.CompositeRouter
router(Bank.Accounts.Router)
router(Bank.MoneyTransfer.Router)
end
One or more routers or composite routers can be included in a
Ming.CommandProcessor
since it is also a composite router:
defmodule BankCommandProcessor do
use Ming.CommandProcessor
router(Bank.Router)
end
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.send(command)
Or via the composite router itself, specifying the application:
:ok = Bank.AppRouter.publish(command, application: BankApp)
A composite router can include composite routers.
Summary
Functions
Register a Commanded.Commands.Router
module within this composite router.