Skip to content

Lightweight dependency injection for TypeScript ☕️

License

Notifications You must be signed in to change notification settings

Frazier-Software/di

Repository files navigation

@fraziersoft/di ☕️

Lightweight dependency injection for TypeScript
Explore the docs »


Issues Coverage MIT License LinkedIn

About The Project

Automatic dependency injection for TypeScript projects. Supports advanced use cases through easy, flexible configuration.

(back to top)

Getting Started

Prerequisites

Install the reflect-metadata and @fraziersoft/di packages.

  • npm
    npm install -D reflect-metadata @fraziersoft/di
  • yarn
    yarn add -D reflect-metadata @fraziersoft/di

Enable decorator support in your project's tsconfig.json file.

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Example

import 'reflect-metadata';
import { create, Injectable } from '@fraziersoft/di';

class Ninja {
  attack() {
    console.log('The Ninja Attacks!');
  }
}

@Injectable()
class Game {
  constructor(public ninja: Ninja) {}

  play() {
    this.ninja.attack();
  }
}

const app = create(Game);
app.play();

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)