Dependency Injection
Overview
Pipelex uses dependency injection to manage service dependencies and make components more modular and testable. The system allows you to customize and extend Pipelex's functionality by injecting your own implementations of various services.
Injection Methods
There are two main ways to inject custom implementations:
1. During Initialization
from pipelex.pipelex import Pipelex
pipelex = Pipelex.make(
reporting_delegate=MyReportingDelegate(),
secrets_provider=MySecretsProvider(),
content_generator=MyContentGenerator(),
pipe_router=MyPipeRouter()
)
2. Through the Hub
from pipelex.hub import PipelexHub
hub = PipelexHub()
hub.set_report_delegate(MyReportingDelegate())
# ... and so on for other components
Protocol Compliance
All custom implementations MUST:
- Implement ALL methods defined in their respective protocols
- Match the exact method signatures (parameter names and types)
- Follow the protocol's documented behavior
- Handle errors appropriately
- Clean up resources when needed
Available Injectable Components
Pipelex supports injection of the following components:
Reporting Delegate (ReportingManager)
- Protocol:
ReportingProtocol - Default:
ReportingManager - No-op option: inject
ReportingNoOpto disable reporting explicitly - Details
Secrets Provider (EnvSecretsProvider)
- Protocol:
SecretsProviderAbstract - Default:
EnvSecretsProvider - Details
Content Generator (ContentGenerator)
- Protocol:
ContentGeneratorProtocol - Default:
ContentGenerator - Details
Pipe Router (PipeRouter)
- Protocol:
PipeRouterProtocol - Default:
PipeRouter - Details