Next.js overview
The Next.js integration keeps dependency injection aligned with the boundary that actually owns a service. It does not create a global container or move a server container into the browser.
Choose a boundary
Section titled “Choose a boundary”| Next.js boundary | Use | Lifetime |
|---|---|---|
| Server Components and nested RSC | di-craft/next/server with React cache |
One container per render pass |
| Route Handlers and Server Actions | runWithRequestContainer() |
One explicitly disposed container per callback |
| Deep Node.js async calls | di-craft/node |
One AsyncLocalStorage scope per callback |
| Client Components | di-craft/next/client |
A separate client container restored from serializable state |
These containers are intentionally different:
RSC render container != Server Action containerRSC render container != Route Handler containerserver container != client containerEntry points
Section titled “Entry points”import { createNextDi, dehydrate } from "di-craft/next/server";import { hydrate } from "di-craft/next/client";Shared hydration types such as Hydratable, HydrationSchema, and
HydrationSnapshot are exported from both Next.js entry points.
Guides
Section titled “Guides”- Use DI in Server Components
- Scope Route Handlers and Server Actions
- Share request scope with AsyncLocalStorage
- Hydrate client state
Deliberate limits
Section titled “Deliberate limits”The adapter does not add React or Next.js to the core package, infer dependencies from runtime types, replace Next.js data fetching, or hydrate a server DI container in the browser.