I have read the guidelines on creating a library and am uncertain how best to pass opts and configure my library. I have also looked at Ecto, Broadway, and the generated Telemetry supervisor in a Phoenix app as references.
- I have a standalone Elixir library (1.14.0 / OTP 25) -
Foo - It has a supervision tree created with
mix new foo --sup Foo.Applicationadds children for a registry and a dynamic supervisorFoo.MixProjecthasmod: {Foo.Application, []}
Options
Application.get_envnot recommended- have a module in the parent with a
useor@behaviorinto the lib
Say in the parent app:
defmodule Bar.Foo do
use Foo # or @behaviour Foo
...
end
aside: use vs behavior
I don’t care which really is used; the library documentation can have a code snippet to paste into a parent for start_link and child_spec, or those can be already implemented in the macro.
Questions / thoughts:
- If Bar.Foo is added to the parent apps supervision tree I can add config options
- Do I keep the
mod: {Foo.Application, []}or remove it and letBar.Foohandle the setup? - But what about the
Foo.Applicationsupervision setup? - Can I reuse that somehow?
- Is there an easier way to do this?
Thanks






















