Mortar

Dependency Injection

If you are unfamiliar with the concept, please read about it.

Mortar is heavily based on this principle. There are different libraries to achieve that in Go.

Mortar uses Uber-FX and you’re strongly encouraged to read all about it.

Well, actually you kinda have to.

To summarize, this is what you need to understand about IoC frameworks:

  • You are not the one creating the dependencies, Uber-FX does it for you. Just tell it how.
  • Every dependency is a Singleton, hence that same instance is reused everywhere.
  • Once your dependencies are defined as an interface, it’s really easy to swap it. Especially during tests.
  • There is no magic, only implicits.