Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match requested interfaces in InvokeStruct #93

Open
GuillaumeDesforges opened this issue Oct 31, 2024 · 0 comments
Open

Match requested interfaces in InvokeStruct #93

GuillaumeDesforges opened this issue Oct 31, 2024 · 0 comments

Comments

@GuillaumeDesforges
Copy link

When I try to declare a dependency in a struct using an interface, do fails to match that interface in InvokeStruct.

package main

import (
	"fmt"

	"github.com/samber/do/v2"
)

type ISvc interface {
	Bar()
}

type Svc struct{}

func (s *Svc) Bar() {}

type Foo struct {
	Svc ISvc `do:""`
}

func main() {
	injector := do.New()
	do.ProvideValue(injector, Svc{})
	s := do.MustInvokeStruct[Foo](injector)
	fmt.Printf("%+v\n", s)
}

gives

panic: DI: could not find service `main.ISvc`, available services: `main.Svc`

It would be most useful if do could automatically match interfaces in InvokeStruct like it does for InvokeAs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant