As we have seen, config injection can be used with both constructors and functions, It is, therefore, possible to build a system with only config injection. Unfortunately, config injection does have some disadvantages.
Passing config instead of abstract dependencies leaks implementation details—Consider the following code:
type PeopleFilterConfig interface { DSN() string}func PeopleFilter(cfg PeopleFilterConfig, filter string) ([]Person, error) { // load people loader := &PersonLoader{} people, err := loader.LoadAll(cfg) if err != nil { return nil, err } // filter people out := []Person{} for _, person := range people { if strings.Contains(person.Name, filter) { out = append(out, person) } } return out, ...