webiny-dependency-injection
ما الذي تفعله
تشرح هذه المهارة النمط المشترك الذي تستخدمه كل امتدادات Webiny للحصول على خدماتها. وهي لمطورين يكتبون أي امتداد لـWebiny ويحتاجون إلى فهم كيفية حصول كودهم على التبعيات.
متى تستخدمها
- ✓عندما تكتب أي امتداد لـWebiny وتحتاج إلى الوصول إلى مسجِّل أو سياق هوية.
- ✓عندما تحتاج إلى استدعاء عمليات إنشاء أو تحديث أو حذف في CMS من كودك.
- ✓عندما لا تعرف كيف تعمل قائمة التبعيات (dependencies).
رابط المهارة
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/dependency-injection/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“أرني كيف أحقن المسجِّل وحالات استخدام إدخالات CMS في صنف امتداد Webiny الخاص بي.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تشرح المهارة الخطوات نفسها لكل أنواع الامتدادات: اكتب صنفًا يطبّق الواجهة المطابقة، وأعلن تبعياته في المُنشئ (constructor)، وصدّره مع المصنع وقائمة التبعيات المطابقين.
المحتوى التقني (ملف 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
- الترخيص
- —
- آخر تحديث
- 2/11/2026
التعليقات
- …
المزيد من المهارات من هذا المستودع
prd-to-plan
8.1kيساعد وكيلك على تحويل وثيقة متطلبات منتج إلى خطة مرحلية من شرائح صغيرة متكاملة من البداية إلى النهاية، تُحفظ كملف Markdown.
webiny-admin-architect
8.1kيعلّم وكيلك بناء شاشات الإدارة لمنصة Webiny، باستخدام طبقات منطق العمل وأسلوب الـpresenter.
webiny-admin-permissions
8.1kيعلّم وكيلك إضافة ضوابط الصلاحيات إلى شاشات إدارة Webiny، مع نماذج صلاحيات مولَّدة تلقائيًا وفحوص لإظهار الأجزاء أو إخفائها.
webiny-form-model
8.1kيعلّم وكيلك بناء النماذج في Webiny باستخدام منشئ حقول تصريحي، مع التخطيطات والتحقق والقواعد الشرطية.
مهارات مشابهة
api-connector-builder
280kيبني وكيلك اتصالات API جديدة على النمط الموجود، ويفيد عندما تحتاج إلى تكامل إضافي دون ابتكار طريقة جديدة للعمل.
api-design
280kيساعد وكيلك على تصميم واجهات REST API وفق أفضل الممارسات، ويوضح كيف تتواصل وكيف تُعرض الأخطاء وكيف تُنظَّم البيانات.
backend-patterns
280kيساعد وكيلك على أنماط بنية الخادم وتحسين قاعدة البيانات، ويفيد في بناء الشيفرة التي تعمل على الخادم أو مراجعتها.