Boundary, Core, or Script?
Learn the role of Boundary, Core and Script in this lesson.
We'll cover the following...
As we add new functions, we can think about them in this way: any function
that deals with process machinery (think “input/output”) or uncertainty will
go in the boundary, or context. Functions that have certainty and support
the boundary go in the core. Scripts that support operational tasks, such as
running tests, migrations, or seeds, live outside the lib
codebase altogether.
Let’s dive a little deeper.
The context API is for with
The context module is the API for a service. Now we know that the context module acts as the application’s boundary layer. Boundary layers handle uncertainty. This is why one of the responsibilities of the context is to manage the database interactions, for example—database requests can fail.
In Elixir, we can use with
statements to manage code flow that contains uncertainty. The with/1
function allows us to compose a series of function calls while providing an option to execute if a given function’s return doesn’t match a corresponding expectation. Reach for ...