ContainerProvider
The ContainerProvider component makes the Brandi container available to any nested components that need to use injections.
The useInjection hook can then access the provided container via React's Context.
Props#
container:Containerโ the provider will not pass the orginal container, but its clone received from theContainer.clone()method (This can be useful together with using the container scope). This behavior is implemented so that the provider can safely extends the container with a container received from the upstream provider. In this way, we can implement a hierarchical DI system based on a hierarchy of React components.[isolated]:booleanโ as mentioned above, the provider extends the container with a container received from the upstream provider.isolatedprop disables this behavior.children:ReactNode.
Examples#
Providing Root Container#
Providing a Module's Own Container#
The container of this module will automatically access the root container from the previous example.
Thus the module components can request a dependency by TOKENS.apiService token and get it from the parent container.