Dependency Injection in AI Parsing Module
This section covers the dependency injection (DI) mechanisms used in the AI Parsing module to manage and provide access to the ExtractorFactory across different components of the system.
Overview
The AI Parsing module utilizes dependency injection to ensure that the ExtractorFactory is available wherever it's needed without tight coupling between components. This is achieved through two key constructs:
-
ExtractorFactoryAwareInterface: Defines a contract that any class needing access to theExtractorFactorymust implement. It requires implementing a single methodsetAiExtractorFactory()that accepts anExtractorFactoryinstance. -
ExtractorFactorySetterTrait: Provides a default implementation of theExtractorFactoryAwareinterface. Classes can use this trait to quickly gain the ability to store and access anExtractorFactoryinstance without writing boilerplate code.
This design pattern is particularly useful for:
- Maintaining loose coupling between components
- Making it easy to mock dependencies during testing
- Ensuring consistent access to the factory throughout the application
Technické informace
ExtractorFactoryAware Interface
- Namespace:
Espo\Modules\AiParsing\Core\Di - Method:
setAiExtractorFactory(AiExtractorFactory $aiExtractorFactory): void - Sets the ExtractorFactory instance that the implementing class will use
- Parameter:
$aiExtractorFactory- An instance ofExtractorFactory
ExtractorFactorySetter Trait
- Namespace:
Espo\Modules\AiParsing\Core\Di - Property:
protected AiExtractorFactory $aiExtractorFactory - Stores the ExtractorFactory instance
- Method:
setAiExtractorFactory(AiExtractorFactory $aiExtractorFactory): void - Implements the interface method to set the factory instance
- Same parameters as the interface method