How do you start a module based on where the project is run?

I’m working on a little library application which means that it does not have an Application callback. However, when I run iex -S mix inside the library application I’d like to start up some modules for testing. That seems like it should be very possible but I can’t figure out how to without resorting to using the application configuration which seems like it may be the wrong choice for this bit of code.

What do you mean by “starting modules”?

Modules aren’t started, they are loaded as soon as they are used for the first time.

If you mean to start a supervisor or genserver that is implemented in that module, you can use your modules API to start and init those.

Also, in my opinion, its nothing wrong to have an application callback even in library packages. A proper application callback does make it a lot easier for the consumer of your library. I’d prefer to just add the dependency and let the runtime take care for everything over having to start your supervision tree in my code.

…unless that supervision tree is busy or consumes significant resources right after startup. In that case instead of returning {:ok, pid} from your start_link, you can just return :ignore based on flags in config.exs.

Yeah that was incorrect terminology. I mean starting processes (where those processes are a mix of supervisors and genservers).

But where would I start them?

Yeah that’s definitely understandable, but in this case I want to use a Repo that the main application controls from inside the library application. If I just use a standard application callback then the Library application’s supervision tree will start before the Repo does.

From iex

Dependencies should be started before your application does.