Hubert Łępicki
Elixir Warsaw 2016-06-09
defmodule CqrsExample do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
supervisor(AggregateSupervisor, [[name: Wallets]])
supervisor(AggregateSupervisor, [[name: Accounts]])
supervisor(AggregateSupervisor, [[name: Products]])
supervisor(AggregateSupervisor, [[name: Services]])
]
opts = [strategy: :one_for_one, name: CqrsExample.Supervisor]
Supervisor.start_link(children, opts)
end
end
defmodule AggregateSupervisor do
def start_link([name: aggregate_name]) do
import Supervisor.Spec
children = [
worker(aggregate_for_name(aggregate_name), [])
]
Supervisor.start_link(
children,
[strategy: :simple_one_for_one, name: aggregate_name]
)
end
def get_aggregate(name, id) do
...
end
defp aggregate_for_name(name) do
...
end
end