DitoxNrgyExtension.tsx
Purpose
This module provides DitoxNrgyExtension, a component that connects a ditox-react container to Nrgy controller and view-model creation inside a React tree.
Overview
The component is intended for applications where controllers or view models use @nrgyjs/ditox extensions such as withContainer() or withInjections(). It removes the need to pass provideDependencyContainer() manually at every controller creation site.
Conceptual Architecture
The implementation acts as a bridge between three packages:
useDependencyContainer()reads the active container fromditox-react.provideDependencyContainer(container)stores the container in Nrgy extension params.NrgyControllerExtensionpublishes the provider through React context, anduseController()from@nrgyjs/reactconsumes it during controller creation.
The helper DitoxInjectionParamsProvider runs during controller construction and guarantees that the DI container is taken from the current React environment.
Public API Description
DitoxNrgyExtension: FC<PropsWithChildren>
children: React subtree whose controllers and view models should receive aditoxcontainer automatically.- Returns
NrgyControllerExtensionconfigured with the bridge provider betweenditox-reactand Nrgy.
Usage Examples
tsx
import React from 'react';
import { DitoxNrgyExtension } from '@nrgyjs/ditox-react';
import { CustomDependencyContainer } from 'ditox-react';
export function Root() {
return (
<CustomDependencyContainer container={container}>
<DitoxNrgyExtension>
<App />
</DitoxNrgyExtension>
</CustomDependencyContainer>
);
}