wire icon indicating copy to clipboard operation
wire copied to clipboard

unknown pattern

Open LFernandoC opened this issue 3 years ago • 5 comments

Struct Providers occurs "unknown pattern", Case:

package domain_service
...
func ProvidePRDomainService() ProcurementRequestDomainService {
	return ProcurementRequestDomainService{
	}
}
...




package main
...


type ProcurementRequestServiceImpl struct {
	prDomainService domain_service.ProcurementRequestDomainService
}

func InitializePRService() ProcurementRequestServiceImpl {
	panic(wire.Build(domain_service.ProvidePRDomainService(), wire.Struct(new(ProcurementRequestServiceImpl),"*")))
}

...

LFernandoC avatar Jan 21 '22 01:01 LFernandoC

with version " github.com/google/wire v0.5.0 "

LFernandoC avatar Jan 21 '22 01:01 LFernandoC

ask for help~!!

LFernandoC avatar Jan 25 '22 06:01 LFernandoC

Is there a import cycle in your project? occur "unknown pattern" when having a import cycle like:

 import cycle not allowed
 package .../cmd/task
    imports .../sku/intern/impl
    imports .../sku
    imports .../sku/task
    imports .../sku

wire works fine when I fix the import cycle

ruo- avatar Feb 12 '22 17:02 ruo-

panic(wire.Build(domain_service.ProvidePRDomainService(), wire.Struct(new(ProcurementRequestServiceImpl),"*"))) should be panic(wire.Build(domain_service.ProvidePRDomainService, wire.Struct(new(ProcurementRequestServiceImpl),"*")))

Note domain_service.ProvidePRDomainService should not be invoked, wire.Build expects a provider, not the thing returned by the provider :)

@LFernandoC can you confirm if this fixes things for you?

jayzhuang avatar Apr 17 '22 23:04 jayzhuang

您的邮件已收到!

ruo- avatar Apr 17 '22 23:04 ruo-