Skip to content

Inject the gift-links service into the API controller at boot#28788

Draft
rob-ghost wants to merge 1 commit into
mainfrom
chore/gift-links-inject-service-at-boot
Draft

Inject the gift-links service into the API controller at boot#28788
rob-ghost wants to merge 1 commit into
mainfrom
chore/gift-links-inject-service-at-boot

Conversation

@rob-ghost

@rob-ghost rob-ghost commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Problem

The gift-links API controller read its service from a mutable module export that is undefined until a boot-time init() ran, so every handler needed a non-null assertion. The service was also instantiated lazily inside its own module rather than wired by the boot sequence, so a future second dependant couldn't easily share the same instance.

Solution

Make boot the composition root: it constructs the service against the ready DB and passes it straight to the controller factory (createController(service)), which closes over a definite instance. The non-null assertions, the init() indirection, and the mutable service singleton all go away. The only shared slot is the built controller, which the API endpoints index reads — the framework loads controllers lazily, so the boot-built one has to live somewhere it can find.

Verified: typecheck and lint clean, and the e2e-api suite (which boots Ghost through this exact path) passes.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 53054a96-088b-40f3-aa71-36e8af25b997

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/gift-links-inject-service-at-boot

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 22, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit f60c2fe

Command Status Duration Result
nx run ghost:test:ci:integration:no-coverage ✅ Succeeded 2m 33s View ↗
nx run ghost:test:ci:integration ✅ Succeeded 2m 20s View ↗
nx build @tryghost/sodo-search ✅ Succeeded <1s View ↗
nx build @tryghost/admin-toolbar ✅ Succeeded <1s View ↗
nx build @tryghost/signup-form ✅ Succeeded <1s View ↗
nx build @tryghost/announcement-bar ✅ Succeeded <1s View ↗
nx build @tryghost/activitypub ✅ Succeeded 2s View ↗
nx build @tryghost/comments-ui ✅ Succeeded <1s View ↗
Additional runs (10) ✅ Succeeded ... View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-22 20:24:05 UTC

Boot constructs the service against the ready DB and passes it straight to
the controller factory; the controller closes over a definite instance, so the
non-null assertions and the lazy init()/singleton are both gone.
@rob-ghost rob-ghost changed the title Inject the gift-links service into the API controller at load Inject the gift-links service into the API controller at boot Jun 22, 2026
@rob-ghost rob-ghost force-pushed the chore/gift-links-inject-service-at-boot branch from e6d877e to f60c2fe Compare June 22, 2026 20:16
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