JSPM

@byteshift/injector

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 163
  • Score
    100M100P100Q82252F
  • License MIT

A tiny dependency injection library

Package Exports

  • @byteshift/injector

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@byteshift/injector) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Byteshift Injector is a tiny Dependency Injection library designed to be used with TypeScript. It utilizes the reflect-metadata package to automatically inject singleton instances of 'services' into a property of any class upon instantiation.

Install through NPM:

$ npm i @byteshift/injector

or through Yarn:

$ yarn add @byteshift/injector

Define a service using the @Service decorator:

import {Service} from '@byteshift/injector';

@Service
export class DatabaseService
{
    public query(sql: string): any;
}

Inject the service using the @Inject decorator on a property.

export class RegistrationForm
{
    @Inject private readonly db: DatabaseService;

    constructor()
    {
        // Access it as you would expect it to work.
        this.db.query('SELECT * FROM ...');
    }
}