linkd.ext.connectrpc

Extension module adding support for using linkd-based dependency injection with ConnectRPC.

See the examples directory for a full working application using this module.

Note

Unlike the FastAPI and Starlette integrations, the default inject() method will work for method handlers when using this extension.


final class Contexts[source]

Collection of the dependency injection context values linkd.ext.connectrpc uses.

REQUEST = 'linkd.contexts.http.request'

DI context used during ConnectRPC request handling.

ROOT = 'linkd.contexts.root'

The root DI context - ALL other contexts are built with this as the parent.

class DiInterceptor(manager: DependencyInjectionManager)[source]

Server interceptor which handles setting up a DI context for each ConnectRPC request.

The ROOT and REQUEST contexts are entered for the duration of every RPC, across all four cardinalities (unary-unary, unary-stream, stream-unary, and stream-stream). Within the request context, the active connectrpc.request.RequestContext is registered as a dependency - as is the request message (google.protobuf.message.Message) for the unary-request RPCs.

Parameters:

manager – The dependency injection manager to use when entering the DI context.

Example

import linkd

manager = linkd.DependencyInjectionManager()

server = YourASGIApplication(
    YourService(),
    interceptors=[linkd.ext.connectrpc.DiInterceptor(manager)],
)