transiant
-
.net core에서 IServiceScopeFactory를 써야할 때프로그래밍 2025. 2. 7. 22:34
IoC Container에 등록된 서비스의 라이프 사이클이 다를 때 사용한다. AService라는 클래스가 등록될 때 Singleton이고BService라는 클래스가 등록될 때 Scope라면 AService는 BService를 참조할 수 없다. 즉, Singleton인 클래스는 하위 lifecycle에 해당하는 클래스 참조가 불가능하다. 따라서 참조 우선 순위는 Transiant 대표적으로 WorkerService 작성시 Service를 Scope, Transiant 로 등록할 경우 Worker에서 주입 받을 때 IServiceScopeFactory를 사용해서 주입받게 된다. 생각해보면 Singleton이 Instance가 메모리에 유일 존재일 때 (즉, 프로그램이 종료하기 전까지 해제 할 수 없는 ..