@guarapi/di-container
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

@guarapi/di-container

CI license Coverage Status npm version

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-container

Usage

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 value

Contributing

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.

Readme

Keywords

Package Sidebar

Install

npm i @guarapi/di-container

Weekly Downloads

0

Version

0.1.4

License

MIT

Unpacked Size

7.98 kB

Total Files

5

Last publish

Collaborators

  • joaoneto