fxutil

package
v0.2.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseOptions added in v0.2.0

func ParseOptions(opts ...Option) (fx.Option, error)

ParseOptions parses multiple given instances of Option and coverts them into a fx.Option.

func WithLifecycle

func WithLifecycle(ctx context.Context, lc fx.Lifecycle) context.Context

WithLifecycle wraps a context to be canceled when the lifecycle stops.

Types

type Option added in v0.2.0

type Option func(*fxOptions) error

Option mimics fx.Option but provides one more OverrideSupply feature.

func Invoke added in v0.2.0

func Invoke(vals ...interface{}) Option

Invoke mimics fx.Invoke.

func InvokeIf

func InvokeIf(cond bool, function interface{}) Option

InvokeIf invokes a given function if a condition is met.

func Options added in v0.2.0

func Options(opts ...Option) Option

Options combines multiples options into a one Option.

func OverrideSupply added in v0.2.0

func OverrideSupply(vals ...interface{}) Option

OverrideSupply overwrites values passed to Provide and Supply. It mimics fx.Supply with one difference - it does not error if there are multiple instances of a type are supplied/provided. Instead, OverrideSupply forces the supply and overrides other Supply and Provide.

Only one overriding must exist for a type.

Only recvs ptr to a value or an interface. To override an interface a ptr to the interface should be provided:

var r io.Reader
OverrideSupply(&r)

and not:

var r io.Reader
OverrideSupply(r)

Otherwise, real value of r will be provided, e.g. *bytes.Buffer.

func Provide added in v0.2.0

func Provide(vals ...interface{}) Option

Provide mimics fx.Provide. Provided ctors can be overridden by OverrideSupply.

func ProvideAs

func ProvideAs(val interface{}, as ...interface{}) Option

ProvideAs mimics fx.Provide(fx.Annotate(fx.As())).

func ProvideIf

func ProvideIf(cond bool, ctor ...interface{}) Option

ProvideIf provides a given constructor if a condition is met.

func Supply added in v0.2.0

func Supply(vals ...interface{}) Option

Supply mimics fx.Supply.

func SupplyAs added in v0.2.0

func SupplyAs(val interface{}, as interface{}) Option

SupplyAs mimics fx.Supply(fx.Annotate(fx.As())).

func SupplyIf

func SupplyIf(cond bool, val ...interface{}) Option

SupplyIf supplies DI if a condition is met.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL