Well, here it comes:
One thing you probably should be very aware is the application/0
function inside your project config. It is not really necessary to have it, but if you don’t have it, you are basically saying: my application has no other dependency at runtime (yes, the deps
method is just for compile time dependencies), and nothing special happens on it.
Now a little more details of what I would put on this method. First, for the PGCommon
project, the method would be a little bit like:
def application do
[applications: [:logger, :ecto],
mod: {PGCommon, []}]
end
Basically this tells Elixir this application depends from logger
and ecto
applications at runtime, and that the module you should invoke to start the application is the PGCommon
module (note: this module must implement the callbacks for the Application
module, and this is where you should put the supervisor startup).
Then, in the applications that depend on PGCommon
, this is the function I would put:
def application do
[applications: [:logger, :pg_common]]
end
As you probably noticed, the pg_common
is a runtime dependency now. This will grant the logger
and pg_common
applications will be started before the application itself starts. And, as you put the supervisor that starts your Repo
on the startup of the pg_common
application in the mod
key above, you can be sure it will be started even before your application start.
So, this basically respond your question. If you have any other doubt about the application/0
method from the project config, you can run mix help compile.app
, it have some other configurations for your application that can be pretty useful.