v0.9.0
Constructors can be handed over as they are written, and the graph they
declare can be checked before anything is built (#3). Nothing existing
changes shape or behaviour; an upgrade cannot break a caller.
go doc -all against 0.8.0 adds Scope.Wire, Scope.Validate, Validation
with its Err method, and dihttp.Validate, and changes no signature. The
README no longer promises no reflection at all: Wire reads a constructor's
signature once at registration and calls it through reflect.Call; Provide
is as it was.
Added
Scope.Wire[T](ctor)registers a plain constructor,func(A, B) Tor
func(A, B) (T, error), whose parameters are its dependencies. Each is
resolved as aProvideclosure would resolve it, from the same scope, so
lifetimes, hooks, cycles and error paths are unchanged. The signature is
read with reflection once at registration, where a constructor of the wrong
shape is rejected like any other configuration error; a result merely
assignable toTis accepted, so a concrete constructor can serve an
interface key. The build calls the constructor throughreflect.Call, about
150ns and two allocations over a closure.Provideis untouched.Scope.Validate()walks the declared graph without building and returns a
Validation:Errors(joined byErr()) for a dependency nothing provides,
a cycle amongWireconstructors, or a singleton that would build aScoped
service in a scope that cannot satisfy it;Owedfor what aScoped
binding needs that the validating scope does not provide, since the scope
resolving it may;Uncheckedfor theProvideclosures.dihttp.Validate(app)validates from a throwaway request scope holding an
*http.Request, so what a request scope would still miss is an error.