elixir-toniq / vapor

Runtime configuration system for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help me understand purpose of the `load` function

stevensonmt opened this issue · comments

I do not understand what Vapor.Provider.load or Vapor.Provider.load! actually does. My assumption was that the load function would apply the configuration to the application environment. This does not seem to be the case as I need to manually apply Application.put_env to set individual configuration attributes. I'm clearly misunderstanding the premise of load (and perhaps Vapor itself) and would appreciate any clarification.

The load function takes a list of providers and loads the values that they provide.

The return value is a map of the bindings specified by the providers. Once you have this, you can do whatever you'd like with them, including putting them into Application configuration if you so desire.

The purpose of Vapor is to provide easy and flexible runtime configuration, usually through environment variables (The Env provider). It will also load a .env file for you in dev and test. Usually one will load their config at runtime, and pass those values to a child in your supervision tree, like an Endpoint or a Repo.

Vapor also provides a somewhat declarative interface for runtime configuration.

My assumption was that the load function would apply the configuration to the application environment.

I would be curious as to what lead you to this assumption. I could help us with documentation.

Thanks for the quick response. I think including the return type in the documentation would have clued me in. I see it now in the source code but didn't catch it earlier. As to the basis of my assumption, I think it's just my implicit understanding of "loading" data as putting it into a spot that you can later retrieve it from. Like you load a car for a trip and then you get what you need back out when you need it. It's also probably just a reflection of inexperience and misunderstanding what a config provider does. I guess the best way for me to think of it is that the config provider provides an opportunity for an application to access attributes, one way being putting the attributes in the application env.