I think your suggestion focused on the “config.exs” part. Your suggestion is to do something like:
defmodule MyApp.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
{MyLibrary, my_library()}
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
defp my_library do
# my library options
end
end
This helps with: any System.get_env() (or fetch_env()) will work on any environment as this is called on application boot. Although this does not say much about multiple instances.
With that it also makes it a bit more inconvenient for per-environment settings. Think you have a client of a service that has a sandbox and a production environment. You want to hit sandbox while you are running locally, but on your deploy you want to hit production. In this scenario you would probably delegate to config.exs although using your own otp_app.
With multiple instances it would become something like:
defmodule MyClient1 do
use MyLibraryClient, otp_app: :my_app
end
defmodule MyClient2 do
use MyLibraryClient, otp_app: :my_app
end
defmodule MyApp.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
{MyClient1, my_credentials_1()},
{MyClient2, my_credentials_2()},
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
defp my_credentials_1 do
# my library options
end
defp my_credentials_2 do
# my library options 2
end
end
I think 99% of the libraries are not using this approach currently ad maybe we should add some link on the Elixir page about that. Also, this is maybe some overhead for a process-less library (IMHO I’d still think this is meaningless overhead).
Also, that might make using this library as a depency of another library a little harder.
When you say:
Building a library that is re-usable without collisions is often much more difficult. But I think it pays off in the long run.
You mean library authors think we should always account for the multiple instances? That is my current opinion too.






















