Kurisu

Kurisu

Is there a way to use in umbrella children the same package with different configurations?

I know that some packages (like Pow) are designed to have their configuration per otp_app but unfortunately not all. For example I would like to use scrivener_html as stated here with different view style per umbrella web app, but don’t know how.

For packages like these (that don’t support configuration per otp_app), how one could manage to use them in umbrella children? Maybe a way to import them twice with different aliases?

Marked As Solved

LostKobrakai

LostKobrakai

Imho this is not at all related to umbrellas, but it’s a problem of library architecture. Even without an umbrella there might be a need to have different configuration to be used with a library. This is never supported when the only way to supply configuration is via the app env.

https://hexdocs.pm/elixir/library-guidelines.html#avoid-application-configuration

For scrivener_html this is not a problem though because you can supply config as a parameter:

# MyAppWeb.ex
def scrivener_config do
  Application.get_env(:my_app, :scrivener_html, [])
end

# In a view
import Scrivener.HTML
pagination_links @conn, @page, [], MyAppWeb.scrivener_config()

# MyOtherAppWeb.ex
def scrivener_config do
  Application.get_env(:my_other_app, :scrivener_html, [])
end

# In a view
import Scrivener.HTML
pagination_links @conn, @page, [], MyOtherAppWeb.scrivener_config()

One short function and one is no longer dependent on how scrivener_html does load config and it would work just as well if the issue is not two apps in an umbrella, but rather a “small width” pagination vs. a “wide” pagination.

Also Liked

wolf4earth

wolf4earth

Depending on how exactly the package in question fetches it’s configuration you’re out of luck. Some packages offer a init callback hook, others allow to specify configuration when adding their process to your supervision tree.

In the case of scrivener_html it seems you’re out of luck.

This is one of the disadvantages of using an umbrella application, configuration can get difficult. Since you need different configuration per application maybe this is a sign that you might want to reconsider having them in the same umbrella?

NobbZ

NobbZ

No.

Only a single configuration is loaded, and if you have multiple config for a single application, they will get merged, and the new config statement will overwrite configuration values on conflict.

You’ll need to find a way to pass in config per call in those applications.

Where Next?

Popular in Questions Top

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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

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
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New

We're in Beta

About us Mission Statement