공부
typedi로 의존성 관리 해보기
코딩이좋아요
2023. 4. 6. 16:08
npm i typedi@0.8.0
/* 기본 사용 법*/
import { Container } from'typedi'
class Test {
constructor(){
console.log("생성")
}
Method() {
return "hi"
}
}
/*
Container.get(클래스 이름)
따로 등록하지 않아도 알아서 등록 후 가져옴
*/
const TesteClassInstance = Container.get(Test)
console.log(TesteClassInstance.Method())
/* 등록후 사용하기 */
Container.set('Test',new Test())
const TesteClassInstance2 = Container.get('Test')
console.log(TesteClassInstance2.Method())