Skip to content

X-Profiler/injection

Repository files navigation

injection

codecov Node.js CI License

An IoC implemention for xprofiler.

Usage

Decorator

import { Injectable, Inject } from "@xprofiler/injection";
import { Config } from "./config";

@Injectable()
export class Foo {
  @Inject()
  private config: Config;

  getKmsConfig(@Inject('KMS_KEY') key: string) {
    return this.config[key];
  }
}

Container

import { Container } from "@xprofiler/injection";
import { Foo, Bar } from "./items";

const container = new Container();

container.set(Foo);
container.set(Bar);

const foo = container.get(Foo);
const bar = container.get(Bar);