Skip to main content

Function: fastifyDbContext()

fastifyDbContext<TContext>(fastify, opts): Promise<void>

Defined in: src/di/fastify.ts:21

Fastify plugin that attaches a scoped DbContext instance to request.dbContext. Automatically disposes the context on the onResponse hook if autoDispose is enabled (default true).

Usage:

fastify.register(fastifyDbContext, { contextClass: AppDbContext, options: dbOptions });
// or shorthand:
fastify.register(fastifyDbContext, AppDbContext);

Type Parameters​

Type Parameter
TContext extends DbContext

Parameters​

ParameterType
fastifyany
optsFastifyDbContextOptions<TContext> | ((options?) => TContext)

Returns​

Promise<void>