November 2018
Intermediate to advanced
346 pages
8h 12m
English
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 MyStructfunc 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 ...
Read now
Unlock full access