TypeScript Dependency Injection 도구

오픈소스·2023년 3월 7일
0
post-thumbnail
post-custom-banner
  • Tsyringe
  • TypeDI
  • Inversify

모두 tsconfig.json를 설정하여야 합니다.

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

그리고, 모두 reflect-metadata package에 의존적입니다.


Tsyringe

import { autoInjectable, inject, injectable } from "tsyringe";

import "reflect-metadata"; // index.ts
import { container } from 'tsyringe';

TypeDI

import { Service } from 'typedi';

import "reflect-metadata"; // app.ts or loader.ts
import { Container } from 'typedi';

https://docs.typestack.community/typedi/02-basic-usage-guide#registering-dependencies

Registering dependencies

There are three ways to register your dependencies:

    1. annotating a class with the @Service() decorator
  • Container.set()
      1. registering a value with a Token()
      1. registering a value with a string identifier

Inversify

import { injectable, inject } from "inversify";

import "reflect-metadata";
import { Container } from "inversify";

참고)

post-custom-banner

0개의 댓글