Wrap Supervisor in module

So I am implementing FunWithFlags, an amazing lib to have feature flags in an app.

I’d like to write a “boundary” layer, i.e. a module that would wrap the whole logic of feature flags for my app, an be the only source exposed in my app, so that if ever I get rid of FunWithFlags for another solution, all I would have to do is update that boundary layer module.

However, I’d like to have better control over FunWithFlag, and must add its supervisor to my application.ex start/2 function, as the application start behaviour of the FWF doc explains.

Therefore instead of adding FunWithFlags.Surpervisor, I’d like to add MyApp.FeatureFlag.Supervisor, which under the hood in my MyApp.FeatureFlag boundary module, would call FunWithFlags.Surpervisor.

Is this possible? then how?

Hope my explanation is clear, let me know if I have to add any further information!

1 Like

When you are defining a module in application.ex, all you are doing is giving it the name of the module which is just an atom. The atom can come from anywhere.

Try adding a supervisor function in your boundary layer that returns the function. Call that from your application.ex to “inject” the right supervisor

defmodule Boundary do

   ...

  def supervisor do
       Library.Supervisor
  end
end

Then in application replace Library.Supervisor with Boundary.supervisor()

2 Likes

Indeed that’s just what I was looking for. Should have known module names are basically atoms.

That’s perfect thank you very much for your help!

2 Likes

Ecto.Repo is the same as :"Elixir.Ecto.Repo".

It’s just syntactic sugar.

1 Like