0.1.4 • Published 2 years ago
@guarapi/di-container v0.1.4
@guarapi/di-container
This is a lightweight and flexible dependency injection (DI) container library for JavaScript and TypeScript applications. It provides a simple yet powerful way to manage and resolve dependencies within your projects.
Installation
You can install the package via npm or yarn:
pnpm add @guarapi/di-container
# or
npm install @guarapi/di-container
# or
yarn add @guarapi/di-containerUsage
Creating Dependency Keys
First, you need to create symbols to act as keys for your dependencies using the createDependencyKey function:
import { createDependencyKey } from '@guarapi/di-container';
const myDependencyKey = createDependencyKey<string>('myDependency');Setting Dependencies
Then, you can set dependencies in the container using the set method:
import Container from '@guarapi/di-container';
const container = new Container()
.set(myDependencyKey, () => 'Dependency value');Getting Dependencies
Finally, you can retrieve dependencies from the container using the get method:
const dependencyValue = container.get(myDependencyKey);
console.log(dependencyValue); // Output: Dependency valueContributing
Contributions are welcome! Please feel free to submit any issues or pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.