AshDispatch.EventRegistry (AshDispatch v0.5.0)
View SourceAuto-discovery registry for event modules.
This module eliminates the need for manual event_modules configuration by
automatically discovering events from Ash domains at runtime.
How It Works
- Scans all configured Ash domains for the given
otp_app - Finds resources with
AshDispatch.Resourceextension - Reads event definitions from the
dispatchDSL section - Returns event information including any associated modules
Usage
Instead of manually configuring:
# OLD - Manual config (no longer needed!)
config :ash_dispatch, :event_modules, [
{"order.created", MyApp.Events.OrderCreated},
{"ticket.assigned", MyApp.Events.TicketAssigned}
]Events are now auto-discovered:
# Get all event modules (for backward compatibility)
EventRegistry.get_event_modules()
# Find a specific event
{:ok, event} = EventRegistry.find_event("order.created")
# Find module for an event
{:ok, module} = EventRegistry.find_module("order.created")Configuration
The registry uses the :otp_app config to know which app's domains to scan:
config :ash_dispatch, :otp_app, :my_appAnd the app must have domains configured:
config :my_app, :ash_domains, [MyApp.Orders, MyApp.Tickets]
Summary
Functions
Get all events from all resources in the configured domains.
Get all event modules for a specific otp_app.
Find an event by its event_id.
Find the module for an event by its event_id.
Get all event modules in the format [{event_id, module}, ...].
Functions
Get all events from all resources in the configured domains.
Returns a list of event info maps with:
:event_id- The event identifier (e.g., "order.created"):name- The event name atom (e.g., :created):module- The event module (if any):resource- The resource module that defines this event:channels- Channel configurations from DSL:content- Content configuration from DSL:metadata- Metadata configuration from DSL
Get all event modules for a specific otp_app.
Returns a list of {event_id, module} tuples for events that have modules.
Events without modules (pure inline DSL) are excluded.
Find an event by its event_id.
Returns {:ok, event_info} or {:error, :not_found}.
Find the module for an event by its event_id.
Returns {:ok, module}, {:error, :no_module} if event exists but has no module,
or {:error, :not_found} if event doesn't exist.
Get all event modules in the format [{event_id, module}, ...].
This provides backward compatibility with the old :event_modules config format.
Only returns events that have an associated module (explicit or generated).
Uses the configured :otp_app to determine which domains to scan.