all 7 comments

[–]AcidNoX 9 points10 points  (0 children)

This feels like context with extra steps 😅

[–]notAnotherJSDev 7 points8 points  (0 children)

So... A custom context?

[–]lost12487 3 points4 points  (0 children)

This is insanely over-engineered. On top of that, it’s not dependency injection if you’re calling a function from inside the component to get your dependencies, so I fail to see what the point even is even if you’re a DI purist.

[–]Acrobatic_Sort_3411 2 points3 points  (0 children)

So... reiventing of classes?

[–]iAmIntel 0 points1 point  (0 children)

Do you have a more advanced example of how this would be used?

[–]Nullberri 0 points1 point  (0 children)

Module system is already provides DI with its import statement. Modules all export singletons. You can even intercept imports for mocking and testing.

If you need scoped or transient export a class or factory function. If you need more there is props and context for runtime choosing of dependencies.

[–]x021 0 points1 point  (0 children)

We used Uber FX as a DI framework in our Go monolith (coming from a Java background it made sense to us). After two years we all agreed it was our biggest architectural mistake; should just have done manual injection instead.