Skip to content

support method provider #294

@sin5th

Description

@sin5th

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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions