lucdoe / opengateway

API Gateway written in Go for small to mid-sized projects. Easy setup, extendable with plugins, and fully customisable.
Apache License 2.0
5 stars 0 forks source link

Decide on DIP implementation #1

Closed lucdoe closed 1 month ago

lucdoe commented 1 month ago

My idea was to think about a dependency injection straight from the start. I stumbled upon Wire and considered using that. This article explains why that might be a good idea.

lucdoe commented 1 month ago

I found this comment in the wire docs:

Should I use Wire for small applications? Probably not. Wire is designed to automate more intricate setup code found in larger applications. For small applications, hand-wiring dependencies is simpler.

lucdoe commented 1 month ago

I also want to improve with DIP, so I will probably go with the approach of doing it myself.

lucdoe commented 1 month ago

Decision: handwire the dependencies.

lucdoe commented 1 month ago

An important point of injecting dependencies is to avoid injecting implementations (structs), you should inject abstractions (interfaces). It’s the letter D of S.O.L.I.D: Dependency Inversion Principle. It allows you to switch easily the implementation of some dependency and, you could change the real implementation for a mock implementation. It's fundamental for unit testing.

See: https://medium.com/avenue-tech/dependency-injection-in-go-35293ef7b6