-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbetter-phoenix-contexts.html
74 lines (72 loc) · 2.61 KB
/
better-phoenix-contexts.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<title>Designing Better Phoenix App Architecture with Contexts</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="./styles/output.css"
type="text/css"
media="screen"
/>
<script
defer
data-domain="aswinmohan.me"
data-api="/stats/api/event"
src="/stats/js/script.js"
></script>
</head>
<body>
<header class="flex items-center justify-between">
<p><a href="/">back to home</a></p>
<p>2022-Apr-29</p>
</header>
<article>
<h1>Designing Better Phoenix App Architecture with Contexts</h1>
<ul>
<li>Introduction</li>
<li>Why we need contexts ?</li>
<li>
Why Contexts are difficult ? Because they are a business problem. They
require you to understand the business
</li>
<li>Fundemental Idea of Contexts ?</li>
<li>How to Structure Contexts?</li>
<li>Make them easy to change, because they will</li>
<li>Test the Contexts</li>
<li>Umberlla Applications?</li>
<li>Conclusion</li>
</ul>
<p>
I came a from a rails background to Elixir and Phoenix. I was used to
writing code that accesed the models and the database directly in the
controller. After learning about the best practices of Fat Models and
Controllers, I switched to writing out the logic in models. When I first
came to learn Phoenix I found teh indirection of Contexts unappealing.
Why do we need to write out a function to access something when we could
directly call that.
</p>
<p>
I reluctantly used to write contexts. If wasn't until I read
<a
href="https://pragprog.com/titles/jgotp/designing-elixir-systems-with-otp/"
>Designing Elixir Systems with OTP
</a>
that writing Elixir Apps with Contexts came clear to me.
</p>
<section>
<h2>Why do we need Contexts? or Phoenix is not your Application</h2>
<p>
When you generated a new project using Phoenix 1.3, you didn't have
the notion of contexts. You just had a top level web directory. You
wrote your code that accessed your databse most probably in your
controllers and that might have served you well when you were starting
out.
</p>
</section>
</article>
</body>
</html>