Saltar al contenido
Skillpedia
APIs y servidores (backend)8,1 mil · #12599

webiny-dependency-injection

Qué hace

Esta habilidad explica el patrón común que usa cada extensión de Webiny para obtener sus servicios. Es para desarrolladores que escriben cualquier extensión de Webiny y necesitan entender cómo llega cada dependencia a su código.

Cuándo usarla

  • ✓Cuando escribes cualquier extensión de Webiny y necesitas acceder a un logger o al contexto de identidad.
  • ✓Cuando necesitas llamar a operaciones de crear, actualizar o borrar del CMS desde tu código.
  • ✓Cuando no tienes claro cómo funciona la lista de dependencias.

Link de la skill

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

Cópialo y pégalo en tu IA (Claude, ChatGPT o Cursor) pidiéndole que siga las instrucciones.

Cómo usar

La forma más fácil: copia el mensaje y pégalo en tu IA. Ella lee la skill y sigue las instrucciones.

Mensaje listo para pegar

Usa esta skill para ayudarme: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/dependency-injection/SKILL.md Lee el archivo SKILL.md de ese link y sigue sus instrucciones en mi tarea.
¿Quieres que tu IA encuentre skills como esta por sí sola?Instala el MCP gratis de Skillpedia: una línea, y busca entre 15.000+ skills antes de cada tarea.Instalar en 1 minuto →

Ejemplo de qué pedirle a la IA

“Muéstrame cómo inyectar el logger y los casos de uso de entradas del CMS en la clase de mi extensión de Webiny.”

5 skills nuevas por semana. 1 minuto de lectura.

Cómo funciona

La habilidad explica los mismos pasos para cada tipo de extensión: escribir una clase con la interfaz correspondiente, declarar sus dependencias en el constructor y exportarla con la fábrica y la lista de dependencias correspondientes.

Contenido técnico (SKILL.md original)

Texto original del autor, en inglés, directo de 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
Preguntas frecuentes

¿Cuáles son las partes del patrón?

Una clase que implementa la interfaz, las dependencias del constructor, y la fábrica exportada con su lista de dependencias.

¿Funciona con todos los tipos de extensión?

Sí. La habilidad indica que se aplica a extensiones de API, de administración, de CLI y de infraestructura.

¿Qué servicios se pueden inyectar?

Por ejemplo, el logger, los parámetros de compilación, el contexto de identidad y los casos de uso de entradas del CMS.

Detalles

Descripción original del autor

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

Popularidad

Estrellas en GitHub
8,1 mil
Posición en el ranking
#12599
Licencia
—
Actualizada
2/11/2026

¿Te sirve esta skill?

0

Entra para votar.

Comentarios

  • …

Más skills de este repositorio

Skills parecidas