View Source Sorcery.Service (Sorcery v0.1.0)
Defines a service that can handle events from domains. Services are used to handle side effects (like sending emails) or to maintain read models (views).
Auto-Starting
Services can be configured to auto-start when your application boots. This ensures that no events are missed and read models stay consistent.
Configure auto-starting in your config:
config :sorcery, :auto_start,
services: [
MyApp.NotificationService,
MyApp.ReadModelService
]Services not configured for auto-start must be started manually.
Example
defmodule MyApp.NotificationService do
use Sorcery.Service
service do
on UserRegistered do
send_welcome_email(event)
end
on OrderPlaced do
send_order_confirmation(event)
end
end
defp send_welcome_email(event) do
# Send email logic
end
defp send_order_confirmation(event) do
# Send confirmation logic
end
end