Hi,
I'm wondering how I can inject dependncies (databases, services etc) into generic functions. Ideally, I would like a struct and an interfface so I can mock it correctly but haven't been able to do it.
type Fulfilment interface {
*TestStruct
SetWhatever()
)
func Transform[T Fulfilment](order Order) T {
var fufilment T
return fufilment
}
func (o *TestStruct) DoWhatever() {}
type TestStruct struct {}
This works, but I can't find a way to add external dependncies that is not on TestStruct
type TestStruct struct {}
func Inject() func[T Fulfilment](order Order) T {
// I'm getting Function type cannot have type parameters
}
