refactor(blog): binders take BindContext arg

This commit is contained in:
2026-05-09 12:40:58 +02:00
parent ab8ca08307
commit fe85976440
3 changed files with 12 additions and 28 deletions

View File

@@ -34,7 +34,7 @@ describe("bindDevSeedBlog", () => {
}); });
it("populates the repository with the dev articles", async () => { it("populates the repository with the dev articles", async () => {
await bindDevSeedBlog(tracer, logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); await bindDevSeedBlog({ tracer, logger, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() });
const repo = blogContainer.get<IArticlesRepository>( const repo = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository, BLOG_SYMBOLS.IArticlesRepository,
@@ -45,7 +45,7 @@ describe("bindDevSeedBlog", () => {
}); });
it("seeds the welcome article reachable by slug", async () => { it("seeds the welcome article reachable by slug", async () => {
await bindDevSeedBlog(tracer, logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); await bindDevSeedBlog({ tracer, logger, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() });
const repo = blogContainer.get<IArticlesRepository>( const repo = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository, BLOG_SYMBOLS.IArticlesRepository,
@@ -58,13 +58,13 @@ describe("bindDevSeedBlog", () => {
}); });
it("is idempotent — calling twice rebuilds a fresh populated repo", async () => { it("is idempotent — calling twice rebuilds a fresh populated repo", async () => {
await bindDevSeedBlog(tracer, logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); await bindDevSeedBlog({ tracer, logger, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() });
const before = blogContainer.get<IArticlesRepository>( const before = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository, BLOG_SYMBOLS.IArticlesRepository,
); );
const beforeCount = (await before.getArticles()).length; const beforeCount = (await before.getArticles()).length;
await bindDevSeedBlog(tracer, logger, new RecordingEventBus(), new RecordingJobQueue(), new RecordingRealtimeBroadcaster(), new RealtimeHandlerRegistry()); await bindDevSeedBlog({ tracer, logger, bus: new RecordingEventBus(), queue: new RecordingJobQueue(), realtime: new RecordingRealtimeBroadcaster(), realtimeRegistry: new RealtimeHandlerRegistry() });
const after = blogContainer.get<IArticlesRepository>( const after = blogContainer.get<IArticlesRepository>(
BLOG_SYMBOLS.IArticlesRepository, BLOG_SYMBOLS.IArticlesRepository,
); );

View File

@@ -5,9 +5,7 @@ import {
type ITracer, type ITracer,
type ILogger, type ILogger,
} from "@repo/core-shared/instrumentation"; } from "@repo/core-shared/instrumentation";
import type { IEventBus } from "@repo/core-events"; import type { BindContext } from "@repo/core-shared/di";
import type { IRealtimeBroadcaster, IRealtimeHandlerRegistry } from "@repo/core-realtime";
import type { IJobQueue } from "@repo/core-shared/jobs";
import { blogContainer } from "./container.js"; import { blogContainer } from "./container.js";
import { BLOG_SYMBOLS } from "./symbols.js"; import { BLOG_SYMBOLS } from "./symbols.js";
import { MockArticlesRepository } from "../infrastructure/repositories/articles.repository.mock.js"; import { MockArticlesRepository } from "../infrastructure/repositories/articles.repository.mock.js";
@@ -30,14 +28,9 @@ import type { IArticlesRepository } from "../application/repositories/articles.r
* Idempotent: safe to call multiple times; each call rebuilds a fresh * Idempotent: safe to call multiple times; each call rebuilds a fresh
* populated repo and rebinds the symbol. * populated repo and rebinds the symbol.
*/ */
export async function bindDevSeedBlog( export async function bindDevSeedBlog(ctx: BindContext): Promise<void> {
tracer: ITracer, const { tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx;
logger: ILogger,
bus: IEventBus,
queue: IJobQueue,
realtime: IRealtimeBroadcaster,
realtimeRegistry: IRealtimeHandlerRegistry,
): Promise<void> {
// Bind shared instrumentation into feature container // Bind shared instrumentation into feature container
if (blogContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) { if (blogContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
blogContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER); blogContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER);

View File

@@ -1,4 +1,3 @@
import type { SanitizedConfig } from "payload";
import { import {
withSpan, withSpan,
withCapture, withCapture,
@@ -6,9 +5,7 @@ import {
type ITracer, type ITracer,
type ILogger, type ILogger,
} from "@repo/core-shared/instrumentation"; } from "@repo/core-shared/instrumentation";
import type { IEventBus } from "@repo/core-events"; import type { BindProductionContext } from "@repo/core-shared/di";
import type { IRealtimeBroadcaster, IRealtimeHandlerRegistry } from "@repo/core-realtime";
import type { IJobQueue } from "@repo/core-shared/jobs";
import { blogContainer } from "./container"; import { blogContainer } from "./container";
import { BLOG_SYMBOLS } from "./symbols"; import { BLOG_SYMBOLS } from "./symbols";
import { ArticlesRepository } from "../infrastructure/repositories/articles.repository"; import { ArticlesRepository } from "../infrastructure/repositories/articles.repository";
@@ -19,15 +16,9 @@ import { getArticlesController } from "../interface-adapters/controllers/get-art
import { getArticleBySlugController } from "../interface-adapters/controllers/get-article-by-slug.controller"; import { getArticleBySlugController } from "../interface-adapters/controllers/get-article-by-slug.controller";
import { createArticleController } from "../interface-adapters/controllers/create-article.controller"; import { createArticleController } from "../interface-adapters/controllers/create-article.controller";
export function bindProductionBlog( export function bindProductionBlog(ctx: BindProductionContext): void {
config: SanitizedConfig, const { config, tracer, logger, bus, queue, realtime, realtimeRegistry } = ctx;
tracer: ITracer,
logger: ILogger,
bus: IEventBus,
queue: IJobQueue,
realtime: IRealtimeBroadcaster,
realtimeRegistry: IRealtimeHandlerRegistry,
): void {
// Bind shared instrumentation into feature container // Bind shared instrumentation into feature container
if (blogContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) { if (blogContainer.isBound(INSTRUMENTATION_SYMBOLS.TRACER)) {
blogContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER); blogContainer.unbind(INSTRUMENTATION_SYMBOLS.TRACER);