webiny-dependency-injection
できること
このスキルは、すべてのWebinyの拡張がサービスを受け取るために使う、共通のパターンを説明します。依存関係がどのように渡されるかを理解する必要がある、どのWebinyの拡張も書く開発者向けです。
使う場面
- ✓どのWebinyの拡張を書いていても、ロガーやアイデンティティのコンテキストにアクセスする必要があるとき。
- ✓コードからCMSの作成、更新、削除の操作を呼ぶ必要があるとき。
- ✓依存関係のリストがどう働くかがわからないとき。
スキルのリンク
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/dependency-injection/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
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:
- One class per file -- each extension file exports a single implementation.
- Constructor injection -- dependencies are received as constructor parameters, in the same order as the
dependenciesarray. - Dependencies array -- must exactly match the constructor parameter order and types.
- 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
createImplementationpattern 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
コメント
- …
このリポジトリの他のスキル
prd-to-plan
8.1k製品要件書を、それぞれ端から端まで成立する小さなスライスの段階的な計画に変え、Markdownファイルとして保存するよう、エージェントを支援します。
webiny-admin-architect
8.1kビジネスロジックの層とプレゼンターのパターンを使い、Webinyプラットフォームの管理画面を作る方法をエージェントに教えます。
webiny-admin-permissions
8.1k自動生成される権限フォームや、表示・非表示のチェックを含め、Webinyの管理画面に権限の制御を追加するよう、エージェントに教えます。
webiny-form-model
8.1kビルダーで宣言的にフィールドを定義し、レイアウト、検証、条件付きのルールを使って、Webinyのフォームを作るよう、エージェントに教えます。
似ているスキル
api-connector-builder
280kエージェントが既存のパターンに従って、新しいAPI連携を構築します。新しい方式を作らずに、もう一つ連携を追加したいときに使います。
api-design
280kエージェントがベストプラクティスに沿ってREST APIを設計できるようにします。APIの通信方法、エラーの表示方法、データの整理方法を決めるのに役立ちます。
backend-patterns
280kエージェントのサーバーサイドのアーキテクチャパターンとデータベースの最適化を支援します。サーバー上で動くコードを作成またはレビューするときに役立ちます。