Skip to content

Dependency Injection Container for JavaScript/TypeScript

License

Notifications You must be signed in to change notification settings

guarapi/guarapi-di-container

Repository files navigation

@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.

About

Dependency Injection Container for JavaScript/TypeScript

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published