Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fx.Annotate: Refactor and support fx.Supply (#802)
This changes how we implement fx.Annotate. Rather than generating a constructor when fx.Annotate is called, we now build an internal `fx.annotate` type--a more featureful version of `fx.Annotated`. We then intercept this `fx.annotated` type, similar to how we intercept `fx.Annotated`, and convert it into a constructor on-demand. To build the constructor itself, we rely on the `annotated.Build` method. The Build method operates by splitting annotation into two: - parameter annotation - result annotation For both pieces, we turn annotations into: types []reflect.Type remap func([]reflect.Value) []reflect.Value Where `types` specifies the type of parameters/results for the generated function, and `remap` turns maps function arguments/results from/to the generated function. .--------------------. | generated function | | | | +--------------+ | args ----->| remap params | | | +------.-------+ | | | | | | | | .------v-------. | | | original fn | | | '------.-------' | | | | | | | | +------v-------+ | out <-----| remap output | | | +------.-------+ | '--------------------' Besides providing a cleaner implementation, this lets us implement support for fx.Annotate in fx.Supply with a fairly small change. Resolves #714
- Loading branch information