Skip to content

marvikomo/marv_injector

Repository files navigation

marv_injector

A lightweight dependency injection container for TypeScript/JavaScript for constructor injection.

Installation

Install by npm

npm install --save marv_injector

Modify your tsconfig.json to include the following settings

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

Add a polyfill for the Reflect API (examples below use reflect-metadata). You can use:

The Reflect polyfill import should only be added once, and before DI is used:

// main.ts
import "reflect-metadata";

// Your code here...

API

Marv_injector performs Constructor Injection on the constructors of decorated classes.

Decorators

injector()

Class decorator factory that allows the class' dependencies to be injected at runtime.

Usage

import {injector} from "marv_injector";

@injector()
class Foo {
  constructor(private database: Database) {}
}



# Contributing

This project welcomes contributions and suggestions.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published