karlkfi / inject

Dependency injection library for Go (golang)
Apache License 2.0
80 stars 7 forks source link

ResolveAll() panic deferencing a nil pointer #11

Open drauschenbach opened 6 years ago

drauschenbach commented 6 years ago

I have an optional struct that I want to inject into another struct. So I define the reference as a pointer. ResolveAll() doesn't support this valid struct value and blows up trying to dereference it.

panic: no defined pointer is assignable to the provider argument 2 of type (*mypackage.MyStruct)

goroutine 1 [running]:
myorg/mypackage/myproject/vendor/github.com/karlkfi/inject.autoProvider.Provide(0x1ae7bc0, 0x1c82df8, 0x224d960, 0xc42000e798, 0x1c3cba0, 0xc420412501, 0xc4204142c0)
    /go/src/github.com/myorg/mypackage/myproject/vendor/github.com/karlkfi/inject/auto_provider.go:42 +0x41c
github.com/BixData/bixserver/vendor/github.com/karlkfi/inject.(*autoProvider).Provide(0xc420403990, 0x224d960, 0xc42000e798, 0x1acc6a0, 0xc4204125f0, 0x96)
    <autogenerated>:1 +0x59
myorg/mypackage/myproject/vendor/github.com/karlkfi/inject.(*definition).Resolve(0xc420412090, 0x224d960, 0xc42000e798, 0x1b15860, 0xc4204125f0, 0x96)
    /go/src/github.com/myorg/mypackage/myproject/vendor/github.com/karlkfi/inject/definition.go:48 +0x81
myorg/mypackage/myproject/vendor/github.com/karlkfi/inject.(*graph).ResolveAll(0xc42000e798, 0xb, 0x2296901, 0x22477c0)
    /go/src/github.com/myorg/mypackage/myproject/vendor/github.com/karlkfi/inject/graph.go:91 +0xf9
main.main()
karlkfi commented 6 years ago

Can you provide a minimal example to reproduce the problem?