umbraco-global-context by umbraco/umbraco-cms-backoffice-skills
npx skills add https://github.com/umbraco/umbraco-cms-backoffice-skills --skill umbraco-global-context全局上下文创建了一个共享的、类型安全的数据和功能层,可在整个后台访问。与作用域上下文(如工作区上下文)不同,全局上下文在整个后台会话期间持续存在。使用它们可以在扩展之间共享状态、管理集中式服务或协调通信。注意:在可能的情况下,优先使用更具体的上下文类型 - Umbraco 会谨慎使用全局上下文。
在实施前务必获取最新文档:
上下文 API : 用于理解上下文使用模式
umbraco-context-api状态管理 : 用于上下文内的响应式状态
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
umbraco-state-managementimport { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import type { MyGlobalContext } from './my-global-context.js';
export const MY_GLOBAL_CONTEXT = new UmbContextToken<MyGlobalContext>(
'My.GlobalContext'
);
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { MY_GLOBAL_CONTEXT } from './my-global-context.token.js';
export class MyGlobalContext extends UmbContextBase {
#currentValue = '';
constructor(host: UmbControllerHost) {
super(host, MY_GLOBAL_CONTEXT);
}
getValue(): string {
return this.#currentValue;
}
setValue(value: string): void {
this.#currentValue = value;
}
}
{
"name": "My Global Context Package",
"extensions": [
{
"type": "globalContext",
"alias": "My.GlobalContext",
"name": "My Global Context",
"js": "/App_Plugins/MyPackage/my-global-context.js"
}
]
}
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import { MY_GLOBAL_CONTEXT } from './my-global-context.token.js';
class MyElement extends UmbElementMixin(LitElement) {
#myContext?: MyGlobalContext;
constructor() {
super();
this.consumeContext(MY_GLOBAL_CONTEXT, (instance) => {
this.#myContext = instance;
});
}
}
就是这样!务必获取最新的文档,保持示例简洁,生成完整可运行的代码。
每周安装次数
69
代码仓库
GitHub 星标数
14
首次出现
2026年2月4日
安全审计
安装于
github-copilot50
cursor23
opencode21
codex21
gemini-cli19
amp19
Global contexts create a shared, type-safe layer of data and functions accessible throughout the backoffice. Unlike scoped contexts (like Workspace Contexts), global contexts persist for the entire backoffice session. Use them for sharing state between extensions, managing centralized services, or coordinating communication. Note: Prefer more specific context types when possible - Umbraco uses global contexts sparingly.
Always fetch the latest docs before implementing:
Context API : For understanding context consumption patterns
umbraco-context-apiState Management : For reactive state within contexts
umbraco-state-managementimport { UmbContextToken } from '@umbraco-cms/backoffice/context-api';
import type { MyGlobalContext } from './my-global-context.js';
export const MY_GLOBAL_CONTEXT = new UmbContextToken<MyGlobalContext>(
'My.GlobalContext'
);
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { MY_GLOBAL_CONTEXT } from './my-global-context.token.js';
export class MyGlobalContext extends UmbContextBase {
#currentValue = '';
constructor(host: UmbControllerHost) {
super(host, MY_GLOBAL_CONTEXT);
}
getValue(): string {
return this.#currentValue;
}
setValue(value: string): void {
this.#currentValue = value;
}
}
{
"name": "My Global Context Package",
"extensions": [
{
"type": "globalContext",
"alias": "My.GlobalContext",
"name": "My Global Context",
"js": "/App_Plugins/MyPackage/my-global-context.js"
}
]
}
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api';
import { MY_GLOBAL_CONTEXT } from './my-global-context.token.js';
class MyElement extends UmbElementMixin(LitElement) {
#myContext?: MyGlobalContext;
constructor() {
super();
this.consumeContext(MY_GLOBAL_CONTEXT, (instance) => {
this.#myContext = instance;
});
}
}
That's it! Always fetch fresh docs, keep examples minimal, generate complete working code.
Weekly Installs
69
Repository
GitHub Stars
14
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
github-copilot50
cursor23
opencode21
codex21
gemini-cli19
amp19
TypeORM 开发指南:TypeScript ORM 框架实战教程与数据库设计
546 周安装