본문으로 건너뛰기
Skillpedia
API 및 서버 (백엔드)8.1k · #12599

webiny-dependency-injection

하는 일

이 스킬은 모든 Webiny 확장 기능이 서비스를 받는 공통 패턴을 설명합니다. 확장 기능을 쓰는 개발자가 코드가 의존성을 어떻게 얻는지 이해하도록 돕는 스킬입니다.

사용하는 경우

  • ✓Webiny 확장 기능을 쓰면서 로거나 신원 컨텍스트에 접근해야 할 때.
  • ✓코드에서 CMS 생성, 수정, 삭제 작업을 호출해야 할 때.
  • ✓의존성 목록이 어떻게 동작하는지 잘 모르는 경우.

스킬 링크

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/dependency-injection/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/dependency-injection/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Webiny 확장 클래스에 로거와 CMS 항목 유스케이스를 주입하는 방법을 보여 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 모든 확장 유형에서 같은 단계를 설명합니다. 해당 인터페이스를 구현하는 클래스를 쓰고, 생성자에서 의존성을 선언하며, 맞는 팩토리와 의존성 목록으로 내보냅니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Dependency Injection Patterns

TL;DR

Every Webiny extension type uses the same DI pattern: define a class implementing *.Interface, declare dependencies in the constructor, and export via *.createImplementation({ implementation, dependencies }). The DI container automatically provides the required services, ensures type safety, and validates at compile time. This pattern is the connective tissue across all extension types -- API, Admin, CLI, and Infrastructure.

Working Context

This skill applies to both extension developers (working in extensions/) and core developers (working in packages/). The DI pattern is universal — only the import paths differ.

Extensions (extensions/) Core (packages/)
createAbstraction from "webiny/api" or from "webiny/admin" from "@webiny/feature/api" or from "@webiny/feature/admin"
createFeature from "webiny/api" or from "webiny/admin" from "@webiny/feature/api" or from "@webiny/feature/admin"
Factory imports from "webiny/api/graphql", from "webiny/api/cms/model", etc. Direct package paths: from "@webiny/handler-graphql/...", from "@webiny/api-headless-cms/..."
Catalog paths Use the Import: path Use the Source: path

Detect which context you're in by checking the file path: extensions/ → extension mode, packages/ → core mode. The dependencies array, constructor injection, scoping rules, and all other patterns are identical in both contexts.

The Universal Pattern

import { SomeFactory } from "webiny/some/path";
import { Logger, BuildParams } from "webiny/api";

class MyImplementation implements SomeFactory.Interface {
  constructor(
    private logger: Logger.Interface,
    private buildParams: BuildParams.Interface
  ) {}

  execute(/* factory-specific params */) {
    this.logger.info("Doing something...");
    // buildParams.get() returns T | null — always account for null.
    const value = this.buildParams.get<string>("MY_PARAM");
  }
}

export default SomeFactory.createImplementation({
  implementation: MyImplementation,
  dependencies: [Logger, BuildParams]
});

Key rules:

  1. One class per file -- each extension file exports a single implementation.
  2. Constructor injection -- dependencies are received as constructor parameters, in the same order as the dependencies array.
  3. Dependencies array -- must exactly match the constructor parameter order and types.
  4. Interface types -- always type constructor params as Feature.Interface.

Where This Pattern Appears

Extension Type Factory Import Path
Content Models ModelFactory "webiny/api/cms/model"
GraphQL Schemas GraphQLSchemaFactory "webiny/api/graphql"
API Keys ApiKeyFactory "webiny/api/security"
CLI Commands CliCommandFactory "webiny/cli/command"
Pulumi Handlers CorePulumi "webiny/infra/core"

Event handlers use the same createImplementation pattern but are not injectable dependencies.

Examples Across Extension Types

API Extension (GraphQL Schema with DI)

GraphQL schemas use the builder pattern. The execute method receives a builder and uses addTypeDefs and addResolver to define the schema. Resolver-level DI is declared per-resolver via dependencies in addResolver, resolved at request time from the request-scoped container.

import { GraphQLSchemaFactory } from "webiny/api/graphql";
import { IdentityContext } from "webiny/api/security";

class WhoAmISchema implements GraphQLSchemaFactory.Interface {
  async execute(
    builder: GraphQLSchemaFactory.SchemaBuilder
  ): Promise<GraphQLSchemaFactory.SchemaBuilder> {
    builder.addTypeDefs(/* Gr
자주 묻는 질문

이 패턴의 구성 요소는 무엇인가요?

인터페이스를 구현한 클래스, 생성자 의존성, 그리고 팩토리와 의존성 목록을 내보내는 부분입니다.

모든 확장 유형에서 작동하나요?

네. API, 관리자, CLI, 인프라 확장 기능에 적용된다고 스킬이 설명합니다.

어떤 서비스를 주입할 수 있나요?

로거, 빌드 매개변수, 신원 컨텍스트, CMS 항목 유스케이스 등이 예입니다.

상세 정보

작성자의 원본 설명

The universal createImplementation DI pattern and all injectable services. Use this skill when the developer is writing any Webiny extension and needs to understand dependency injection, constructor injection, how to access Logger/BuildParams/IdentityContext, how to inject CMS use-cases (list/get/create/update/delete entries), or how the dependencies array works. This is the connective tissue across all extension types -- API, Admin, CLI, and Infrastructure.

repo: webiny/webiny-js

인기도

GitHub 스타
8.1k
순위
#12599
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬