tangui
Hi all,
I’m working on a Phoenix project (Asteroid) in which I define some behaviours such as Asteroid.TokenStore.AccessToken. I want to have different implementations in separate libraries, such as
AsteroidTokenStoreAccessTokenMnesiaAsteroidTokenStoreAccessTokenRiak- …
My question is: what’s the best practice to import Asteroid.TokenStore.AccessToken (in lib/token_store/access_token.ex) in my separate libs?
I’ve tried with dependencies:
defmodule AsteroidTokenStoreAccessTokenRiak.MixProject do
...
defp deps do
[
{:asteroid, path: "../asteroid", runtime: false},
....
]
end
end
However, this approach causes 2 problems:
- it imports the whole Phoenix project, dependencies and compiles them all - this is not wanted
- side effect: this results in
endpoint.exof the Phoenix project not compiling because it cannot findPoisonwhich is not loaded (and the configurationconfig :phoenix, :json_library, Jasonin my Phoenix project is lost)
Cheers!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
You cannot do that. If you want to share that behaviours definitions then you need to extract the code to separate library.
gregvaughn
@hauleth is correct. I want to also caution you against premature abstraction. If you try to do all the decoupling steps now while you really don’t even know how to do it, you are going to make your project more complex for yourself. I encourage you to write the application that you need to write. Later, after you’ve used and lived with the code for a while, then look for seams where it might make sense to extract a library.
tangui
Thanks for your answers.
Extracting the code seemed to be the way to go, but while coding I realized that this behaviour uses types and returns structs that are in other modules of the Phoenix project, and moving them also would result in extracting a important amount of modules (not sure where it’d stop).
Wouldn’t I be looking for something similar to C/C++/Erlang header file includes? Afaik there is no such thing in Elixir.
I think I’ll merge it in the core app as suggested, even though I’m not comfortable to include
riak,redis, etc. as dependencies when not needed (but I guessruntime: falseinmix.exswill do the the trick). I’ll post back for suggestions when I’ve some code to show.Cheers
tangui
Now that I have some code to show, here’s an example. The goal is to allow using a behaviour in separate libraries (eg. : a Redis implementation of an access token store). The access token store behaviour of Asteroid refers to type in other modules:
At that point I see 2 options:
Asteroid.Subject.id()andAsteroid.Token.AccessToken.id()types but some more generic ones such asString.t()and extract only the behaviourWhat do you think?