woohaaha
Accessing routes in the domain layer without including MyAppWeb in MyApp context
Hi all,
I am sending lifecycle emails from my the MyApp context. I’m using Bamboo.Template like so:
defmodule MyApp.Notifications do
use Bamboo.Template, view: MyApp.Notifications.Views.EmailView
def welcome(many-params) do
base_email()
|> to(email)
|> subject("Welcome")
|> assign(:user, user)
|> put_text_layout({MyApp.Notifications.Views.EmailView, "welcome.text"})
|> put_text_layout({MyApp.Notifications.Views.EmailView, "welcome.html"})
|> render(:welcome)
|> Mailer.deliver_later()
end
end
The benefit of Bamboo.Template is that I don’t have to include Phoenix web layer concerns or MyAppWeb in the context.
In the welcome.html.eex email I would like to include a url like a verify_email_url or a referral_url.
How do I get the needed url paths, specified in the Router (which is in Web), into my context layer?
Thank you
Most Liked
a8t
I think you should use the path helpers. I know that it feels like it’s breaking the boundary, but the web concern truly is a dependency for this email, no?
davemenninger
Fwiw, this is what I have done too. I just go ahead and use
MyAppWeb.Router.Helpers.some_url(...)
right in MyApp.Email.
bit4bit
hi, may this help towards maintainable elixir the core and the interface section Activation mail using UrlProvider
woohaaha
Thank you for your reply.
but the web concern truly is a dependency for this email, no?
I feel like it’s not that there’s a web concern that’s a dependency, but that there is a dependency IN the web layer that I’d like access to. Perhaps I’m over thinking this but it seems like routes are just strings. They only get meaning and behavior when looked at from a web browser’s perspective. Otherwise, they’re just strings in a certain shape. But yeah, perhaps over thinking.
Looks like I’ll include MyApp web and just finish the feature ![]()
kelvinst
You could always send the url as a parameter to the email logic.







