원클릭으로
dependency-injection
Dependency Injection pattern for service definitions, factories, and composition roots.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Dependency Injection pattern for service definitions, factories, and composition roots.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | dependency-injection |
| description | Dependency Injection pattern for service definitions, factories, and composition roots. |
Some parts of the codebase use the Dependency Injection (DI) pattern. Instead of importing dependencies directly, pass them to the service as parameters. This allows better testability and separation of concerns.
Use this skill mainly for packages that directly mention this skill.
The unified pattern for defining services is as follows.
Define in this order for consistency:
Use the same key (serviceName) everywhere. This is important so Dep, Deps, and composition root wiring stay consistent.
export type ServiceNameDeps = OtherServiceDep | AnotherServiceDep;
export type ServiceParams = {
id: string;
// ...
};
// Usually a function, but it can also be an object with multiple methods.
export type ServiceName = (params: ServiceParams) => ServiceResult;
export type ServiceNameDeps = {
serviceName: ServiceName;
};
Do not repeat ServiceParams in factory ((params) only). It is inferred from ServiceName.
Service factory:
File shall be named: createServiceName.ts.
export const createServiceName =
(deps: ServiceNameDeps): ServiceName =>
params => {
// params is inferred from ServiceName type
return deps.serviceName(params);
};
This is the place where the tree of dependencies is created and wired together.
Composition root:
// Composition root may have its own dependencies
type CompositionRootDeps = ADep;
export const createCompositionRoot = (deps: CompositionRootDeps) => {
const otherService = createOtherService(deps);
const serviceName = createServiceName({ otherService });
return {
serviceName, // expose only `serviceName`; `otherService` is module-private in this case
};
};