Open
Description
- Can't invoke
interface
(can't castnil
)
package main
import "github.com/samber/do/v2"
func main() {
type I interface{}
i := do.New()
do.ProvideValue(i, I("some"))
do.MustInvokeAs[I](i)
}
// panic: DI: could not find service `*main.I`, available services: `*main.I`
- Random invoked, other not checked ([👷] Road to v2 🚀 #45 (comment))
package main
import (
"fmt"
"github.com/samber/do/v2"
)
type I interface{ Name() string }
type i struct{}
func (i) Name() string { return "EXPECTED" }
type other struct{}
func (other) Other() {}
func (other) Name() string { return "OTHER" }
// type
func main() {
scope := do.New()
do.ProvideValue(scope, other{})
do.ProvideValue(scope, i{})
for range 10 {
fmt.Println(do.MustInvokeAs[I](scope).Name())
}
// output: something like
// OTHER
// OTHER
// OTHER
// EXPECTED
// OTHER
// OTHER
// OTHER
// EXPECTED
// OTHER
// OTHER
}
I create a function that would temporarily delete InvokedAs result by OverrideNamedValue and tried to check the next not exist.
But I came across both 1 problem and samber/go-type-to-string#2
Metadata
Metadata
Assignees
Labels
No labels