一键导入
dependency-injection
Dependency Injection pattern for service definitions, factories, and composition roots. Use when working with packages that use the DI pattern.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Dependency Injection pattern for service definitions, factories, and composition roots. Use when working with packages that use the DI pattern.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
publishConfig rules for public npm packages in the Trezor Suite monorepo. Use when adding or editing publishConfig, exports, or preparing a package for npm publishing.
How to create and structure packages in the Trezor Suite monorepo, including scopes and sizing guidance. Use when creating new packages or resolving cyclic dependencies.
Use when writing component or hook tests in suite-native and need to choose between renderWithBasicProvider, renderWithStoreProvider, or store helpers like createStoreFromPreloadedState, createLightStore, or mergePreloadedState.
Generated code must be aligned with security headers (e.g. no unsave JS eval). The permissions policy is especially relevant when changing any code related with the `navigator` object.
Trigger on any mention of Trezor wallet interaction, crypto addresses, sending crypto, checking balances, signing messages, or hardware wallet operations via MCP. Also trigger when users mention configuring or troubleshooting the Trezor MCP server connection.
How to create and implement IndexedDB storage migrations in the Trezor Suite web app. Use when writing migrations that transform persisted data between Suite versions.
| name | dependency-injection |
| description | Dependency Injection pattern for service definitions, factories, and composition roots. Use when working with packages that use the DI pattern. |
Some parts of the codebase use the Dependency Injection (DI) pattern. Instead of importing dependencies directly, pass them to the service as parameters. This allows better testability and separation of concerns.
Use this skill mainly for packages that directly mention this skill.
The unified pattern for defining services is as follows.
Define in this order for consistency:
Use the same key (serviceName) everywhere. This is important so Dep, Deps, and composition root wiring stay consistent.
export type ServiceNameDeps = OtherServiceDep | AnotherServiceDep;
export type ServiceParams = {
id: string;
// ...
};
// Usually a function, but it can also be an object with multiple methods.
export type ServiceName = (params: ServiceParams) => ServiceResult;
export type ServiceNameDeps = {
serviceName: ServiceName;
};
Do not repeat ServiceParams in factory ((params) only). It is inferred from ServiceName.
Service factory:
File shall be named: createServiceName.ts.
export const createServiceName =
(deps: ServiceNameDeps): ServiceName =>
params => {
// params is inferred from ServiceName type
return deps.serviceName(params);
};
This is the place where the tree of dependencies is created and wired together.
Composition root:
// Composition root may have its own dependencies
type CompositionRootDeps = ADep;
export const createCompositionRoot = (deps: CompositionRootDeps) => {
const otherService = createOtherService(deps);
const serviceName = createServiceName({ otherService });
return {
serviceName, // expose only `serviceName`; `otherService` is module-private in this case
};
};