mlcl_di
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Dependency injection for Typescript

mlcl_di is a dependency injection module mainly created for the Molecuel application framework but can be used with any Node project. It's highly inspired by the Spring java framework. The development is focused on simple usage and good code readability.

We also developed an option to define and reuse Singleton instances in your code. We are using the latest features from Typescript, ECMAScript and Reflect Metadata.

Example

import {di, injectable, singleton, component} from 'mlcl_di';

@injectable
class InnerClass {
  constructor() {

  }
}
@injectable
class SomeClass {
  inside: InnerClass;
  constructor(inj: InnerClass) {
    this.inside = inj;
  }
  someMethod(){
    console.log('did something.');
  }
}

@singleton
class MySingletonClass {
  prop: any;
  constructor(inj: SomeClass) {
    this.prop = inj || false;
  }
}

@component
class MyComponent {
  prop: any;
  constructor(inj: SomeClass) {
    this.prop = inj || false;
  }
}

@component
@singleton
class MySingletonComponent {
  prop: any;
  constructor(inj: SomeClass) {
    this.prop = inj || false;
  }
}
// automatically initializes all components and it's dependencies
di.bootstrap();

API Documentation

The current API Documentation can be found on https://molecuel.github.io/mlcl_di/

Readme

Keywords

none

Package Sidebar

Install

npm i mlcl_di

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • dominicboettger