bryanhuntesl
Dependency injection/IOC
A popular Java and C# design pattern is runtime dependency infection.
People tend to associate it with Object Oriented programming but there is nothing inherent to OOP.
Runtime dependency injection/resolution can work for any system that provides a runtime mechanism to override or modify the version of a class or module which has been requested.
It strikes me that Mox provides a limited form of dependency injection in that sense.
Now I’m not advocating for it, but just for the sake of idle discussion (and I do know about Application.env and regular configuration stuff) has anyone ever attempted bringing Java style DI to Elixir?
Most Liked
paulstatezny
I was a fan of dependency injection containers when I was working with object-oriented web frameworks.
I was too, until I spent years of my life diligently writing unit tests, only to realize years later that those tests proved very little about the codebase.
Dependency injection is evangelized because it makes it easier to unit test with mocks.
Integration tests are vital. Unit tests are mostly useful for pure functions. Mocks lead to false confidence about the test suite.
When I came to Elixirland and learned to write mostly integration tests, I was blown away by the amount of real bugs the test suite caught.
hauleth
I just pass modules as a function arguments where needed. In other cases I just do not bother at all.
mudasobwa
Usually, we have a Client behaviour here, declaring a type, and refine the spec to
@typet opts [{:client, Client.t()} | {atom(), any()}]
@spec client_get(String.t(), opts()) :: {:ok, String.t()} | {:error, any()}







