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

support method provider #294

Open
sin5th opened this issue May 31, 2021 · 0 comments · May be fixed by #330
Open

support method provider #294

sin5th opened this issue May 31, 2021 · 0 comments · May be fixed by #330

Comments

@sin5th
Copy link

sin5th commented May 31, 2021

Is your feature request related to a problem? Please describe.

I used to write type method instead of a single NewXxx. eg:

// declare NewDog method, which belong to type Animals

type Animals struct{}

func NewAnimals() *Animals {
	return &Animals{}
}

type Dog struct{}

func (f *Animals) NewDog() *Dog {
	return &Dog{}
}

frustrated when I want to use it as wire provider, I got unknown pattern error. eg:

// wire.go

//+build wireinject
//go:generate wire

func InitDog() *animals.Dog {
	panic(wire.Build(
		animals.NewAnimals,
		(*animals.Animals).NewDog, // this line will trigger error
	))
}

Describe the solution you'd like

I want the above usage could be work. Generated code should looks like:

// wire_gen.go

func InitDog() *animals.Dog {
	animalsAnimals := animals.NewAnimals()
	dog := (*animals.Animals).NewDog(animalsAnimals)
	return dog
}
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

Successfully merging a pull request may close this issue.

1 participant