inxect v0.1.1 Inxect.DI

Macros which replace function arguments with implementations using dependency injection. Use this module to inject dependencies and Inxect.Registry to create a registry.

Summary

Macros

Specify a function where injection should be applied, all the argument names which have been marked for injection with inject/1 will be replaced

Specify a function parameter which should be injected

Macros

defi(head, body)

Specify a function where injection should be applied, all the argument names which have been marked for injection with inject/1 will be replaced.

Example

defi sayHello(who, localizer) do
    { :ok, "\#{localizer.getHello()} \#{who}"}
end

will be compiled like that:

def sayHello(who) do
    p_sayHello(who, resolve(:localizer))
end
defp p_sayHello(who, localizer) do
    {:ok, "\#{localizer.getHello()} \#{who}"}
end

def(test_sayHello(who, localizer)) do
    p_sayHello(who, localizer)
end
inject(inject)

Specs

inject(term, atom) :: nil

Specify a function parameter which should be injected