Cumulative configuration on Mix.Config


In my umbrella app I need to register handler modules to channels in one of the apps, central_registry. I don’t want to start an application just to call the registry, so I was wondering if I could use the mix config for this purpose.

My solution was the following: use the config.exs file of the application (inside the umbrella) to register a new key inside the :central_registry application, but the key must end with _channel in order to work.

For instance, to register the “auth” channel I can declare on its auth_app/config/config.exs

config :central_registry, :auth_channel,
    name: "auth",
    handler: AuthApp.Handler

Similarly, to register the “metrics” channel I can declare on its metrics_app/config/config.exs

config :central_registry, :metrics_channel,
    name: "metrics",
    handler: MetricsApp.Handler

Now, to fetch all the configured channels and handlers, I do the following:

def load_from_config() do
    |> Enum.reduce(%{}, fn ({e, info}, acc) ->
      is_channel = e |> Atom.to_string |> String.ends_with?("_channel")
      has_data = info[:name] != nil and info[:handler] != nil
      if is_channel and has_data do
        Map.put(acc, info[:name], info[:handler])

This function basically parses all config from central_registry app, and reduce it to a map when the value of the key ends with “_channel”.

This work as intended, but I was wondering if is it okay to one application add keys to the config of another application or if there is a better way to do the same thing.