Best practise for configuring Ecto.Repo for an open source module?

I’m working on a yet-to-be-released module for dealing with dual-entry accounting in Elixir/Phoenix apps, and due to its nature, this features a lot of database interaction.

What is the best way to allow the implementing app to provide its Ecto.Repo instance to the module?

I could make it a parameter to all public APIs, so they have to be called like Accounting.add_account(MyApp.Repo, account), but that is a bit inelegant.

Any suggestions for a better way to do this? Maybe configuration?

Built it with passing the repo manually everywhere and then optionally create a using macro to wrap the api for an repo in a userland module.

defmodule MyApp.Accounting do
  use Accounting, repo: MyApp.Repo
end

MyApp.Accounting.add_account(account)
1 Like