Small library to make dependency injection with elixir easier, see documentation for more infos
defmodule Localizer do
@callback getHello :: String.t
end
defmodule Greeter do
use Inxect.DI
inject :localizer
@spec sayHello(String.t) :: { :ok, String.t }
defi sayHello(who, localizer) do
{ :ok, "#{localizer.getHello()} #{who}"}
end
end
defmodule EnglishLocalizer do
@behaviour Localizer
@spec getHello :: String.t
def getHello do
hello
end
end
defmodule Registry do
use Inxect.Registry
register { :localizer, EnglishLocalizer }
end
iex(2)> Greeter.sayHello("Daniel")
{ :ok, "hello Daniel" }