WithQualifierFor sets a named qualifier for the constructor argument that matches the given type T.
(name string)
| 175 | // WithQualifierFor sets a named qualifier for the constructor argument |
| 176 | // that matches the given type T. |
| 177 | func WithQualifierFor[T any](name string) DefinitionOption { |
| 178 | return func(def *Definition) error { |
| 179 | typ := reflect.TypeFor[T]() |
| 180 | objectConstructor := def.constructor |
| 181 | |
| 182 | exists := false |
| 183 | for index, arg := range objectConstructor.Args() { |
| 184 | if arg.Type() == typ { |
| 185 | objectConstructor.args[index].name = name |
| 186 | exists = true |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if !exists { |
| 191 | return fmt.Errorf("no constructor input of type %s", typ.Name()) |
| 192 | } |
| 193 | |
| 194 | return nil |
| 195 | } |
| 196 | } |