baseclass / inxect

dependency injection for elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Small library to make dependency injection with elixir easier, see documentation for more infos

Build

Build Status

Documentation

https://hexdocs.pm/inxect

Hex

Hex.pm Hex.pm

Example

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" }

About

dependency injection for elixir

License:MIT License


Languages

Language:Elixir 100.0%