ContextDependency

class gafaelfawr.dependencies.context.ContextDependency

Bases: object

Provide a per-request context as a FastAPI dependency.

Each request gets a RequestContext. To save overhead, the portions of the context that are shared by all requests are collected into the single process-global ProcessContext and reused with each request.

Attributes Summary

process_context

The underlying process context, primarily for use in tests.

Methods Summary

__call__(request[, session, logger])

Create a per-request context and return it.

aclose()

Clean up the per-process configuration.

initialize(config)

Initialize the process-wide shared context.

Attributes Documentation

process_context

The underlying process context, primarily for use in tests.

Methods Documentation

async __call__(request, session=Depends(DatabaseSessionDependency), logger=Depends(LoggerDependency))

Create a per-request context and return it.

Parameters:
Return type:

RequestContext

async aclose()

Clean up the per-process configuration.

Return type:

None

async initialize(config)

Initialize the process-wide shared context.

Parameters:

config (Config) – Gafaelfawr configuration.

Return type:

None