/dependency-injection
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
Claude Code
$ npx -y skills add webiny/webiny-js --skill dependency-injection --agent claude-code
Codex
$ npx skills add webiny/webiny-js --skill dependency-injection -a codex -y
Cursor
$ npx skills add webiny/webiny-js --skill dependency-injection -a cursor -y
Gemini CLI
$ npx skills add webiny/webiny-js --skill dependency-injection -a gemini-cli -y
GitHub Copilot
$ npx skills add webiny/webiny-js --skill dependency-injection -a github-copilot -y
OpenCode
$ npx skills add webiny/webiny-js --skill dependency-injection -a opencode -y
Windsurf
$ npx skills add webiny/webiny-js --skill dependency-injection -a windsurf -y
SKILL.md
dependency-injection.SKILL.mdname: webiny-dependency-injection
description: >
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.
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(/* GraphQL */ `
extend type Query {
whoAmI: String
}
`);
builder.addResolver({
path: "Query.whoAmI",
dependencies: [IdentityContext],
resolver: (identityContext: IdentityContext.Interface) => {
return () => {
const identity = identityContext.getIdentity();
return `Hello, ${identity.displayName}!`;
};
}
});
return builder;
}
}
export default GraphQLSchemaFactory.createImplementation({
implementation: WhoAmISchema,
dependencies: []
});Register `GraphQLSchemaFactory` implementations with `dependencies: []` and declare resolver dependencies in `addResolver({ dependencies })`. Never inject `IdentityContext`, `TenantContext` or a use case through the factory constructor and read it inside a resolver: the schema is cached across requests, so the resolver would keep the identity, tenant and use cases of the request that built the schema. An anonymous reques
Read more
name: webiny-dependency-injection description: > 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.
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(/* GraphQL */ `
extend type Query {
whoAmI: String
}
`);
builder.addResolver({
path: "Query.whoAmI",
dependencies: [IdentityContext],
resolver: (identityContext: IdentityContext.Interface) => {
return () => {
const identity = identityContext.getIdentity();
return `Hello, ${identity.displayName}!`;
};
}
});
return builder;
}
}
export default GraphQLSchemaFactory.createImplementation({
implementation: WhoAmISchema,
dependencies: []
});Register `GraphQLSchemaFactory` implementations with `dependencies: []` and declare resolver dependencies in `addResolver({ dependencies })`. Never inject `IdentityContext`, `TenantContext` or a use case through the factory constructor and read it inside a resolver: the schema is cached across requests, so the resolver would keep the identity, tenant and use cases of the request that built the schema. An anonymous reques
Open-source content platform. Self-hosted on AWS serverless. Built as a TypeScript framework you extend with code, not a closed product you configure through a UI. Runs on Lambda, DynamoDB, S3, and CloudFront inside your own AWS account. Scales automatically.
Other skills on webiny-js.
More skills from other plugins.
prompt-lookup
Activates when the user asks about AI prompts, needs prompt templates, wants to search for prompts, or mentions prompts.chat. Use…
ppt-master
AI-driven presentation workflow for generating editable PPTX decks and slides, reconstructing page visuals, creating reusable…
morph-ppt
Use this skill when the user wants a .pptx with smooth cross-slide animation — PowerPoint Morph transitions, Keynote-style…
frontend-slides
Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to…
Questions about dependency-injection.
- Which coding agents can use dependency-injection?
- dependency-injection installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.

