Skip to content

Commit

Permalink
docs: use fx.Decorate instead of fx.Replace in examples (#9725)
Browse files Browse the repository at this point in the history
In practice there are cases when fx.Replace doesn't work as expected,
so this updates the documentation to recommend using fx.Decorate
instead which is a bit easier to use.
  • Loading branch information
guseggert authored Mar 20, 2023
1 parent 08dcb28 commit e0b08ed
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ plugin type is likely the best interim solution.
### fx (experimental)

Fx plugins let you customize the [fx](https://pkg.go.dev/go.uber.org/fx) dependency graph and configuration,
by customizing the`fx.Option`s that are passed to `fx` when the IPFS node is initialized.
by customizing the`fx.Option`s that are passed to `fx` when the Kubo node is initialized.

For example, you can inject custom implementations of interfaces such as [exchange.Interface](https://github.com/ipfs/go-ipfs-exchange-interface)
or [pin.Pinner](https://github.com/ipfs/go-ipfs-pinner) by adding an option like `fx.Replace(fx.Annotate(customExchange, fx.As(new(exchange.Interface))))`.
For example, you can override an interface such as [exchange.Interface](https://github.com/ipfs/go-ipfs-exchange-interface)
or [pin.Pinner](https://github.com/ipfs/go-ipfs-pinner) with a custom implementation by appending an option like
`fx.Decorate(func() exchange.Interface { return customExchange })`.

Fx supports some advanced customization. Simple interface replacements like above are unlikely to break in the future,
but the more invasive your changes, the more likely they are to break between releases. Kubo cannot guarantee backwards
compatibility for invasive `fx` customizations.
compatibility for `fx` customizations.

Fx options are applied across every execution of the `ipfs` binary, including:

Expand All @@ -68,7 +69,7 @@ Fx options are applied across every execution of the `ipfs` binary, including:
- etc.

So if you plug in a blockservice that disallows non-allowlisted CIDs, then this may break migrations
that fetch migration code over IPFS.
that fetch migration code over the IPFS network.

### Internal

Expand Down

0 comments on commit e0b08ed

Please sign in to comment.