Config injection is a specific implementation of method and parameter injection. With config injection, we combine multiple dependencies and system-level config and merge them into a config interface.
Consider the following constructor:
// NewLongConstructor is the constructor for MyStruct
func NewLongConstructor(logger Logger, stats Instrumentation, limiter RateLimiter, cache Cache, timeout time.Duration, workers int) *MyStruct {
return &MyStruct{
// code removed
}
}
As you can see, we are injecting multiple dependencies, including a logger, instrumentation, rate limiter, cache, and some configuration.
It is safe to assume that we would be likely to inject at least the logger and the instrumentation into most of our objects in this same project. This results in a minimum of two parameters for every constructor. Across an entire system, this adds up to a lot...