How robak86/hardwired works
Main Components
• Core Library (packages/core): This is the heart of Hardwired containing the DI container implementation. It includes submodules for configuration, dependency definitions (both function-based and class-based), container internals (e.g., the “Configuration”, “Container”, “Interceptors”, “Strategies”, “Context”, and “Utils” directories), and disposal management.
• React Integration (packages/react): Provides React-specific components, hooks, and context wrappers (e.g., ContainerInitializer, ContainerProvider, ContainerScope, and related tests) for integrating the DI container with React applications.
• Examples (packages/examples): A practical HTTP server example that illustrates how the library is used in a real-world scenario.
• Documentation and Configurations: The “docs” folder with drawio files, configuration files (like tsconfig.json, vitest.config.ts, eslint and prettier configs), and CI-related workflows.
Architectural Structure
• Monorepo Organization: The project uses a multi-package structure with a dedicated folder for core functionalities, React-specific integrations, and usage examples.
• Core DI Engine:
• Definitions: The system supports multiple lifetimes—singleton, scoped, and transient—as well as both function-based and class-based definitions. The directories “definitions”, “configuration”, and “container” illustrate these roles.
• Container & Scoping: The container is responsible for both the creation and management of instances along with scoping mechanisms for isolated dependency graphs.
• Interceptors & Strategies: The library includes support for interceptors (logging, dependency graph building, etc.) which decorate or modify the creation process and behavior of the dependency graph.
• Context and Utils: Supporting files (like those under “context” and “utils”) provide runtime mechanisms such as memoization, asynchronous processing, and more.
• React Integration:
• Components: The react package has components for initialization and providing container contexts. It includes tests that validate integration and hooks that ease consumption.
• Testing & Configuration: Broad test coverage across all packages (using vitest) ensures the DI library works as designed in various use cases (type safety, lazy evaluation, etc.).
Essential Elements
• Annotations for design choices such as “lazy evaluation”, “singleton vs. scoped vs. transient”, and “child scope creation”.