Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate how to improve dependency injection in components #802

Open
acelaya opened this issue Feb 16, 2023 · 0 comments
Open

Investigate how to improve dependency injection in components #802

acelaya opened this issue Feb 16, 2023 · 0 comments
Labels
enhancement New feature or request tech-debt

Comments

@acelaya
Copy link
Member

acelaya commented Feb 16, 2023

Some years ago, dependency injection was introduced in the project, via dependency injection container.

The approach works pretty well for services, but it is a bit less convenient for components, specially considering dependency injection is frequently used for redux action creators as well.

These are some of the problems:

  • Components that need non-redux dependencies injected, need to be wrapped in a constructor function.
  • Dependencies can be injected via that function, or via props, if they are action creators or redux state props, making it inconsistent.
  • Once a component needs any kind of injected dependency, it can no longer be imported. Instead, it has to also be injected itself, affecting the whole chain of parent components.

A possible way to solve this would be to create a provider that allows accessing the container via context, and do a sort of dependency location to pass any kind of dependency to components, always via props.

Then we could have a helper function to wrap components that takes care of extracting some services and passing them down to the component.

This has the next benefits:

  • We can always import components, no matter what, allowing to refractor individual components adding/removing injected dependencies, without impacting the parents in the chain.
  • Dependencies would be consistently injected via props.

Possible approaches:

TODO

@acelaya acelaya added enhancement New feature or request tech-debt labels Feb 16, 2023
@acelaya acelaya added this to the 3.10.0 milestone Feb 16, 2023
@acelaya acelaya removed this from the 3.10.0 milestone Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tech-debt
Projects
Status: No status
Development

No branches or pull requests

1 participant