Parameter Binding
The bind parameter allows you to inject infrastructure dependencies (database connections, configuration, auth context) into your endpoint functions without exposing them in the remote function signature.
Why Use Parameter Binding?
When your endpoint needs dependencies like database connections or authentication context, you have two options:
- Framework DI (e.g., FastAPI’s
Depends()): Use this for HTTP endpoints where the framework manages the request lifecycle bindparameter: Use this for SDK endpoints that need dependencies in both local execution and remote testing
Basic Usage
Late Binding with Callables
Use callables (lambdas or functions) for dependencies that should be evaluated fresh on each call:
Real-World Example
Key Concepts
Excluded from Remote Signature
Bound parameters don’t appear in the registered function signature, so remote tests only need to provide business logic parameters:
# Function definition
@endpoint(bind={"db": lambda: get_db(), "config": AppConfig()})
def query_data(db, config, input: str, session_id: str = None):
...
# Remote signature (what tests see)
query_data(input: str, session_id: str = None)Evaluation Timing
- Static values: Evaluated once at decoration time
- Callables: Evaluated fresh on each function call
No Override
Bound parameters won’t override explicitly provided values:
Resource Cleanup
The SDK automatically handles cleanup for generator-based dependencies:
When to Use bind vs Framework DI
Use bind when:
- Building SDK endpoints for remote testing
- Need same dependencies in local execution and remote tests
- Working outside web framework context
- Want dependencies to work seamlessly with Rhesis platform
Use Framework DI (e.g., FastAPI Depends()) when:
- Building HTTP endpoints only
- Framework manages request lifecycle
- Need framework-specific features (request context, middleware)
- Not using Rhesis SDK connector
Can use both: