Skip to content

refactor(appkit): introduce CoreServiceRegistry and ServiceLocator#374

Draft
ditadi wants to merge 1 commit into
mainfrom
stack/taskflow/service-registry
Draft

refactor(appkit): introduce CoreServiceRegistry and ServiceLocator#374
ditadi wants to merge 1 commit into
mainfrom
stack/taskflow/service-registry

Conversation

@ditadi
Copy link
Copy Markdown
Contributor

@ditadi ditadi commented May 11, 2026

🥞 Stacked PR

Use this link to review incremental changes.


AppKit's core previously ran a hardcoded boot sequence for cache + telemetry. This refactor introduces a generic registry so the core no longer names concrete services:

  • CoreServiceFactory<T> — interface every core service implements, returning { instance, shutdown } (or null for intentional opt-outs).
  • CoreServiceRegistry — boots a list of factories in declared order, shuts down in reverse, doubles as a typed locator via get<T>(name).
  • bootstrap-factories.ts — composes the list _createApp boots, living next to the concrete service modules so core/appkit.ts stays free of concrete-class imports.

Cache and Telemetry are migrated to expose .factory() static methods and flow through the registry. Behaviour is identical: same boot order, same shutdown order, same opt-out semantics.

Plugins now receive a typed services: ServiceLocator through attachContext, in addition to the existing per-service fields kept for backwards compatibility (cache, telemetry, plus a taskflow placeholder typed as unknown for forward compat). New plugins should consume services.get<T>(name); the named legacy fields are marked @deprecated.

This PR is groundwork — no behaviour change, no public-API removal. The purpose is to make room for a third core service (TaskFlow) without re-threading the cross-package attachContext contract: adding a new service now only touches the service module and bootstrap-factories.ts. TaskFlow itself is intentionally NOT in this PR; it lands in a follow-up.

Verified: pnpm -r typecheck, pnpm build, full pnpm test (122 files, 2255 tests) all green.

Signed-off-by: ditadi victordperd@gmail.com

AppKit's core previously ran a hardcoded boot sequence for cache +
telemetry. This refactor introduces a generic registry so the core no
longer names concrete services:

- `CoreServiceFactory<T>` — interface every core service implements,
  returning `{ instance, shutdown }` (or `null` for intentional opt-outs).
- `CoreServiceRegistry` — boots a list of factories in declared order,
  shuts down in reverse, doubles as a typed locator via `get<T>(name)`.
- `bootstrap-factories.ts` — composes the list `_createApp` boots,
  living next to the concrete service modules so `core/appkit.ts` stays
  free of concrete-class imports.

Cache and Telemetry are migrated to expose `.factory()` static methods
and flow through the registry. Behaviour is identical: same boot order,
same shutdown order, same opt-out semantics.

Plugins now receive a typed `services: ServiceLocator` through
`attachContext`, in addition to the existing per-service fields kept
for backwards compatibility (`cache`, `telemetry`, plus a `taskflow`
placeholder typed as `unknown` for forward compat). New plugins should
consume `services.get<T>(name)`; the named legacy fields are marked
`@deprecated`.

This PR is groundwork — no behaviour change, no public-API removal.
The purpose is to make room for a third core service (TaskFlow) without
re-threading the cross-package `attachContext` contract: adding a new
service now only touches the service module and `bootstrap-factories.ts`.
TaskFlow itself is intentionally NOT in this PR; it lands in a follow-up.

Verified: pnpm -r typecheck, pnpm build, full pnpm test
(122 files, 2255 tests) all green.

Signed-off-by: ditadi <victordperd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant