-
Couldn't load subscription status.
- Fork 0
Global Container
Getting the global container:
import { Container } from 'packetjs-di';
const globalContainer = Container.getContainer();Note that
getContainer()method is a static method of theContainerclass.
You can also get the global container using the import statement:
// Import the global container using CommonJS modules
const { default: packetJsDi } = require('packetjs-di');
// Import the global container using ES6 imports
import packetJsDi from 'packetjs-di';Register a service using the global container from the import statement:
import packetJsDi from 'packetjs-di';
packetJsDi.add('Service', () => {
return new SomeService();
});Get the service in the application using the global container from the import statement:
import packetJsDi from 'packetjs-di';
const service = packetJsDi.get('Service'); // Instantiate the serviceIn both cases,
packetJsDiwill always have the same global instance of the container. Except in environments rendered in SSR vs CSR, like Next.js, Angular, etc., where the container instance may be different depending on the rendering environment.
We welcome contributions from the community! Whether it's reporting a bug, suggesting a feature, or contributing code, your involvement is key to making Packet.js better. Please check out this section for more details.
If you encounter any issues or bugs while using packetjs, or if you have any feature requests, please feel free to
open an issue in our GitHub repository. You can report issues, track progress, and engage in discussions with the
community via the following link:
If you have any questions or need further assistance, feel free to reach out via the discussion board.