-
Couldn't load subscription status.
- Fork 63
Open
0 / 80 of 8 issues completedMilestone
Description
This includes any instance where we access services using the view context.
The main reasons:
- testable code
- clear dependency management
- unique IoC mechanism (i.e. DI)
This can be done in steps to avoid breaking changes as much as possible:
- Extend the DIG container to provide factories in a similar way as done today:
c.Provide(NewAcceptCashViewFactory, WithInitiators(&WithdrawView{}, &TransferView{}))
c.Provide(NewWithdrawFactory, WithFactoryId("withdrawal"))
- Move
digutils.Registerfrom the core SDKs to the end SDKs (integration-test SDKs). - Ensure DI is used for remaining core components, e.g. viewManager
- Refactor views to support both modes. Example of refactoring
Before
func NewMyView(...) *MyView {...}
type MyView struct {
Wallet string
}
func (v *MyView) Call(ctx view.Context) (interface{}, error) {
...
GetKVS(ctx).Get(...)
GetIdentityProvider(ctx)...
}
After
func NewMyView(...) *myView {}
// Keeps exactly the same inputs as MyView did before for backward compatibility
type myView struct {
Wallet string
}
func (v *myView) Call(ctx view.Context) (interface{}, error) {
return ctx.RunView(&MyView{
Wallet: v.Wallet,
kvss: GetKVS(ctx),
identityProvider: GetIdentityProvider(ctx),
})
}
type MyView struct {
Wallet string
kvss *kvs.KVS
identityProvider driver.IdentityProvider
}
// Is exactly the same method as before, but now the services are provided as fields and not fetched through the ctx
func (v *MyView) Call(ctx view.Context) (interface{}, error) {
...
}
- Remove
RegisterFactory,RegisterResponderfrom the test topology and create SDK's for each node, using the newProvidemethod of the DIG container with the corresponding options explained above. - Removed unused views (e.g.
myView) anddigutils.Registerfrom the integration-test SDKs. - Remove the service provider from the context and any other reference to it.
Sub-issues
Metadata
Metadata
Assignees
Labels
No labels