AshCommanded.Commanded.Transformers.GenerateDomainRouterModule (AshCommanded v0.1.0)

View Source

Generates 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:

  1. Defines dispatch functions for all commands in that domain
  2. 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.before?/1.

Builds the module name for a domain router.

Transforms the DSL state to generate a domain router module.

Functions

after?(arg1)

Specifies that this transformer should run after the command and aggregate module transformers.

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.

before?(_)

Callback implementation for Spark.Dsl.Transformer.before?/1.

build_domain_router_module(domain_module)

Builds the module name for a domain router.

Examples

iex> build_domain_router_module(MyApp.Accounts)
MyApp.Accounts.Router

transform(dsl_state)

Transforms the DSL state to generate a domain router module.

Examples

iex> transform(dsl_state)
{:ok, updated_dsl_state}