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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, maintainers.
Context
I'm working on an API that involves file extraction. The system architecture includes several layers:
FileExtractionControllerFileExtractionServiceFileExtractor(an internal engine)Current Implementation
The
FileExtractorclass is instantiated within theFileExtractionServicewithout dependency injection. However,FileExtractorrequires a repository implementation to be passed in its constructor.Problem Statement
I want to inject dependencies that my API uses indirectly, specifically for the
FileExtractorclass. 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
FileExtractorobject without explicitly passing it through intermediary layers.Current Code Structure
Additional Notes
FileExtractorclass is not directly related to the API; it's an internal component for file content extraction.@injectdecorator (class level or method level).Questions
repositoryin theFileExtractorclass 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