Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate approach #3

Open
Will-W opened this issue Mar 12, 2020 · 1 comment
Open

Alternate approach #3

Will-W opened this issue Mar 12, 2020 · 1 comment

Comments

@Will-W
Copy link

Will-W commented Mar 12, 2020

You are probably aware of this, but there is another approach that you don't address in your README. In this approach, the library provides a 'using' macro that the consumer of the API can use to create a single purpose module with the appropriate parameters.

The mailer 'Swoosh' is a good example of doing this. This is the entire contents of one module in my system:

defmodule DoorstepWeb.Mailer do
  use Swoosh.Mailer, otp_app: :doorstep
end

Then, rather than calling Swoosh directly, I call DoorstepWeb.Mailer and the use directive has created all the API functions I need, with the appropriate adjustments (presumably passing through to equivalent internal functions, adding otp_app as an extra arg).

In this case you would only ever need one implementation, but if it was being used to inject some other form of dependency (like a mailing provider), you might instantiate several and then use the appropriate module in your code.

There is a downside of greppability, and of having a per-library macro burden to make it work. It's quite natural to the consumer though.

[by the way - I hope it's ok to put this here]

@QuinnWilton
Copy link
Owner

QuinnWilton commented Mar 12, 2020

This is a really great suggestion, thank you! It is absolutely okay to put this here :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants