createNextDi · Next.js server API
function createNextDi(options): NextDiAdapter;Creates a server adapter for Next.js App Router and React Server Components.
The root container is created once. getRequestContainer creates a child
container through the provided React request cache, so repeated calls inside
one RSC render pass resolve through the same scoped dependency graph.
Import this helper from a server-only composition file. The adapter does not
import React itself; pass cache from react so React/Next owns render
memoization.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
|
|
React cache function and providers for the server adapter. |
Returns
Section titled “Returns”Helpers for root, render-scoped, and explicit request containers.
Example
Section titled “Example”import "server-only";import { cache } from "react";import { createNextDi } from "di-craft/next/server";
export const { getRequestContainer } = createNextDi({ cache, providers,});Throws
Section titled “Throws”Error when called in a browser runtime.