Skip to main content

DI containers are dead, long live context containers!

· 12 min read
@someone635

Equation banner

info

This story is for you if:

  • You're still sad React Context cannot be used in Server Components.
  • You like the ideas of SOLID architecture and decoupling in your apps but have found current DI frameworks in TypeScript unsatisfying or too complex.
  • You've ever wanted to see a naked, frameworkless DI container in its simplest form (NSFW warning :P).
  • You love TypeScript and enjoy pushing its inference capabilities to their limits.

This is the story of how, while refactoring my React app from Client to Server Components, I was forced to spend a year of my free time to:

  1. rediscover DI containers,
  2. obsolete traditional DI frameworks,
  3. discover Context containers, and
  4. finally, build my own fully type-inferred context container framework, typectx.

A tale of dumb, costly refactoring decisions that I hope produced a useful result in the end :).