woohaaha

woohaaha

Blog post on "Piping Phoenix Contexts", has anyone tried this and can give their experience?

I came across this blog post: https://iacobson.medium.com/piping-phoenix-contexts-3d54dbba8df9

I really like the idea and was wondering if anyone else in the community had thoughts and/or experience with this sort of implementation?

For context ( :smirk:) I have a Phoenix app with 10 contexts (each with variable numbers of models/schemas 2-10 each). I think the contexts are correct as it feels very intuitive and the terminology makes sense (at least for me) but I’m coming across issues where more and more features require multiple contexts to be called. Easiest example I think to understand would be the New User Onboarding requires:

Account.create_user
Organizaton.join
Analytics.track_create_user
Notifications.send_pending_membership_email
Notifications.send_admin_approval_email
+ a few more

I think this blog post describes a process that may make sense as the application grows but I’d like some feedback from people who have experience in this area.

Thank you

First Post!

joaquinalcerro

joaquinalcerro

Depending in your final goals, you can check this options:

  1. The token approach: Advanced Techniques for Architecting Flow in Elixir · rrrene
  2. Ecto Multi: Ecto.Multi — Ecto v3.14.0

For the Ecto Multi option, you can wrap all those functions in a transaction Repo.transaction allowing you to handle a use case if one of the operations fail. Maybe rollback or take other actions.

Check the Multi.run function: Ecto.Multi — Ecto v3.14.0

I have used them both.

Where Next?

Popular in Discussions Top

thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
lucaong
Hello Elixir and Nerves community, I have been working for a while on an open-source embedded key-value database for Elixir, that I call...
230 14027 124
New
lorenzo
Hey everone! I created a prototype for my app using Nodejs for the api. But the framework I chose wasnt great (in general theresnt any g...
New
nburkley
AWS re:Invent is on at the moment with some interesting announcements. One new feature in particular is the Lambda Runtime API for AWS La...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 19652 166
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
und0ck3d
Hello everyone! A few days ago I’ve created a topic here about how people were creating CMSs with Elixir and Phoenix. I’ve been studying...
New
AstonJ
Can you believe the first professionally published Elixir book was published just 8 years ago? Since then I think we’ve seen more books f...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
sashaafm
Piggy backing a bit on @dvcrn topic BEAM optimization for functions with static return type?, I’ve been trying to understand in a deeper ...
New

Other popular topics Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41989 114
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New

We're in Beta

About us Mission Statement