Dependency Injection for Nested Objects in a File Extraction System #239
Replies: 3 comments
-
As for now, I can suggest reading this: https://dishka.readthedocs.io/en/stable/di_intro.html I'llt think about your question later and maybe add more details |
Beta Was this translation helpful? Give feedback.
-
Okay. Thanks. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi, maintainers.
Context
I'm working on an API that involves file extraction. The system architecture includes several layers:
FileExtractionController
FileExtractionService
FileExtractor
(an internal engine)Current Implementation
The
FileExtractor
class is instantiated within theFileExtractionService
without dependency injection. However,FileExtractor
requires a repository implementation to be passed in its constructor.Problem Statement
I want to inject dependencies that my API uses indirectly, specifically for the
FileExtractor
class. The challenge is to avoid passing these dependencies through each layer (Controller -> Service -> FileExtractor).Desired Solution
Implement a mechanism to auto-inject the required dependency (repository) into the
FileExtractor
object without explicitly passing it through intermediary layers.Current Code Structure
Additional Notes
FileExtractor
class is not directly related to the API; it's an internal component for file content extraction.@inject
decorator (class level or method level).Questions
repository
in theFileExtractor
class without modifying the entire object creation chain?Any insights or code examples demonstrating a clean, maintainable solution would be greatly appreciated. I didn't find this kind of thing in the documentation, only things I've found is an @Inject decorator, but all of these decorators are located in the integrations module.. Do I have to call container.get everywhere I need it? Having to import it everywhere I need it
Beta Was this translation helpful? Give feedback.
All reactions