Skip to content

[protocols-trpc] Resolve controllers through Croco DI and request context #1677

Description

@kang-heewon

Priority

P1

Problem

The tRPC adapter constructs controllers with new and never establishes Croco request context. Constructor injection, request-scoped providers, BatchLoad isolation, and request telemetry are bypassed.

Evidence

packages/protocols-trpc/src/libs/createTrpcRouter.ts uses new controllerCtor() and imports neither Container nor Context.

Desired outcome

tRPC procedures resolve controllers and dependencies through the same scoped runtime model as other Croco transports.

Implementation path

  • Add an injectable controller resolver or use the Container at the request boundary.
  • Establish and dispose a request context around each procedure.
  • Propagate tRPC trace/request metadata into that context.

Acceptance criteria

  • Constructor-injected controllers execute through tRPC.
  • Concurrent tRPC calls do not share request-scoped state.
  • Request context is cleaned up after success and failure.

Validation

  • Add DI and concurrent-scope tRPC integration tests.
  • Run pnpm --filter @croco/protocols-trpc test and pnpm typecheck.

Scope

Does not change Container lifetime semantics outside the adapter.

Metadata

Metadata

Assignees

Labels

P1Priority 1 issueapi-contractAPI, RPC, route, and schema contract workbugSomething isn't workingruntimeRuntime behavior, lifecycle, and environment capability work

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions