AshCommanded.Commanded.Transformers.GenerateDomainRouterModule (AshCommanded v0.1.0)
View SourceGenerates a domain-specific router module based on the commands defined in a domain's resources.
For each Ash.Domain containing resources with commands, this transformer will generate a domain router module that:
- Defines dispatch functions for all commands in that domain
- Routes commands to the appropriate aggregate
This transformer should run after the command and aggregate module transformers.
Example
Given a domain with resources that have commands, this transformer will generate:
defmodule MyApp.Accounts.Router do
@moduledoc "Router for commands in the Accounts domain"
use Commanded.Commands.Router
# Register User commands
dispatch [MyApp.Accounts.Commands.RegisterUser, MyApp.Accounts.Commands.UpdateEmail],
to: MyApp.Accounts.UserAggregate,
identity: :id
# Register Account commands
dispatch [MyApp.Accounts.Commands.CreateAccount, MyApp.Accounts.Commands.CloseAccount],
to: MyApp.Accounts.AccountAggregate,
identity: :id
end
Summary
Functions
Specifies that this transformer should run after the command and aggregate module transformers.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0
.
Callback implementation for Spark.Dsl.Transformer.before?/1
.
Builds the module name for a domain router.
Transforms the DSL state to generate a domain router module.
Functions
Specifies that this transformer should run after the command and aggregate module transformers.
Callback implementation for Spark.Dsl.Transformer.after_compile?/0
.
Callback implementation for Spark.Dsl.Transformer.before?/1
.
Builds the module name for a domain router.
Examples
iex> build_domain_router_module(MyApp.Accounts)
MyApp.Accounts.Router
Transforms the DSL state to generate a domain router module.
Examples
iex> transform(dsl_state)
{:ok, updated_dsl_state}