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 import Pipelex
pipelex = Pipelex(
template_provider=MyTemplateProvider(),
llm_model_provider=MyLLMProvider(),
plugin_manager=MyPluginManager(),
inference_manager=MyInferenceManager(),
pipeline_tracker=MyPipelineTracker(),
activity_manager=MyActivityManager(),
reporting_delegate=MyReportingDelegate()
)
pipelex.setup(
secrets_provider=MySecretsProvider(),
content_generator=MyContentGenerator(),
pipe_router=MyPipeRouter()
)
2. Through the Hub
from pipelex.hub import PipelexHub
hub = PipelexHub()
hub.set_template_provider(MyTemplateProvider())
hub.set_llm_models_provider(MyLLMProvider())
hub.set_plugin_manager(MyPluginManager())
# ... and so on for other components
NoOp Implementations
Some components have "NoOp" (No Operation) implementations that are used when the feature is disabled:
ReportingNoOp
: Used when reporting is disabledPipelineTrackerNoOp
: Used when pipeline tracking is disabledActivityManagerNoOp
: Used when activity tracking is disabled
These NoOp implementations implement the same protocol but do nothing, allowing the system to function without the specific feature.
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
Feature Flags
Some components are controlled by feature flags in the configuration:
is_reporting_enabled
: Controls Reporting systemis_pipeline_tracking_enabled
: Controls Pipeline Trackingis_activity_tracking_enabled
: Controls Activity Tracking
When a feature is disabled, the corresponding NoOp implementation is used automatically.
Available Injectable Components
Pipelex supports injection of the following components:
-
Template Provider (
TemplateLibrary
)- Protocol:
TemplateLibraryProtocol
- Default:
TemplateLibrary
- Details
- Protocol:
-
LLM Model Provider (
LLMModelLibrary
)- Protocol:
LLMModelLibraryProtocol
- Default:
LLMModelLibrary
- Details
- Protocol:
-
Plugin Manager (
PluginManager
)- Protocol:
PluginManagerProtocol
- Default:
PluginManager
- Details
- Protocol:
-
Inference Manager (
InferenceManager
)- Protocol:
InferenceManagerProtocol
- Default:
InferenceManager
- Details
- Protocol:
-
Reporting Delegate (
ReportingManager
)- Protocol:
ReportingProtocol
- Default:
ReportingManager
orReportingNoOp
if disabled - Details
- Protocol:
-
Pipeline Tracker (
PipelineTracker
)- Protocol:
PipelineTrackerProtocol
- Default:
PipelineTracker
orPipelineTrackerNoOp
if disabled - Details
- Protocol:
-
Activity Manager (
ActivityManager
)- Protocol:
ActivityManagerProtocol
- Default:
ActivityManager
orActivityManagerNoOp
if disabled - Details
- Protocol:
-
Secrets Provider (
EnvSecretsProvider
)- Protocol:
SecretsProviderProtocol
- Default:
EnvSecretsProvider
- Details
- Protocol:
-
Content Generator (
ContentGenerator
)- Protocol:
ContentGeneratorProtocol
- Default:
ContentGenerator
- Details
- Protocol:
-
Pipe Router (
PipeRouter
)- Protocol:
PipeRouterProtocol
- Default:
PipeRouter
- Details
- Protocol:
Best Practices
⚠️ Under construction