wire
wire copied to clipboard
wire: support function arguments as providers
This doesn't work:
func injectBar(fn func() *Foo) *Bar {
panic(wire.Build(fn, NewBar))
}
It currently panics. I have an easy fix for the panic, but it then results in:
var fn func() *example.com/foo.Foo is not a provider or a provider set
fn
should be usable as a provider for Foo
/*Foo
.
I don't know if I understand the rule that's being introduced here. Is your idea to support using any unnamed function type that is introduced into the dependency graph as a provider? Or just specifically passing arguments to wire.Build
? I'm not sure I see the benefit, even with reviewing google/go-cloud#690.
A provider is just a function no? From the README
, "a function that can produce a value". It seems like wire.Build
should therefore accept various forms of such functions to be used in the provider graph. Why is fn
in the example above not usable? I'm not sure exactly what "unnamed" means -- its name in this context is fn
. What's the rationale for not allowing it?
In terms of the benefit, I tried this out as a workaround for #7. wire.Bind
does not allow methods to be used as providers, and this would be a way to get around that (by passing the method to the injector function and using it that way).
When I tried it it panicked, which is clearly not good. The first PR I sent fixes the panic and saves the error wire
produces.
I'm hoping to fix the panic for this sprint; adding real support for this is a separate discussion.
google/go-cloud#724 fixed the panic and recorded the current error. Deferring till next sprint for more work.