Introduction of a Dependency Injection Framework
See original GitHub issueCurrent Implementation
Right now, The code uses object
Singletons and static methods to access shared data and execute code e.g. [1], [2] and in many more files.
This would make testing so hard as it will make the experience for developers and contributors unpleasant as they would spend more time in writing the mock code rather than testing their actual work. e.g. [3]
Suggested Enhancement
Introduction of a DI framework that will make writing a testable, maintainable and extensible code achievable. The selection of which framework to use is up to the maintainers.
Expected Benefits
These are the points on top of my head, I might be for sure missing some.
- Embracing constructor injected objects rather than the current approach of using
object
singletons, as using Singletons is considered as anti-pattern. - Reducing the memory footprint of the application since the DI framework will take care of scoping of the objects, right now everything is declared
object
and once accessed it will be kept in memory even though it may not be needed anymore after it has served its purpose. - Instrumentation tests would be easier to write since the created test DI Graph will be responsible to provide the dependencies across all the application layers, right now it is impossible to provide a mock network or a Database for example
- Increasing the test coverage point in the README would be easier to achieve as objects will be able to get instantiated through ctor injection hence providing fakes/mocks would be easier.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:21
- Comments:13 (2 by maintainers)
Top Results From Across the Web
A Practical Introduction To Dependency Injection
This article is the first part of an upcoming series that provides a practical introduction to Dependency Injection in a manner that ...
Read more >A Gentle Introduction to Dependency Injection | The Startup
In this article I'll provide a gentle introduction to using Dependency Injection in . NET 5.0.
Read more >Dependency injection - Wikipedia
In software engineering, dependency injection is a design pattern in which an object or function receives other objects or functions that it depends...
Read more >Dependency Injection - TutorialsTeacher
Dependency Injection (DI) is a design pattern used to implement IoC. It allows the creation of dependent objects outside of a class and...
Read more >Design Patterns Explained – Dependency Injection with Code ...
The dependency injection technique. You can introduce interfaces to break the dependencies between higher and lower level classes. If you do ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please do not introduce more complexity as necessary. It is much more difficult to understand the code when Dagger or similar frameworks are used. And it is also possible to do testing without this frameworks. Btw. in my opinion the testing argument is very weak to justify that the code will be obfuscated. Especially for this porject it is very important to keep every thing as simple as possible.
@timo-drick I don’t see how the dependency injection pattern introduces “unnecessary” complexity? Actually you don’t need a framework like Dagger 2 for implementation. The basic pattern is very simple and can be implemented “by hand”. I see many benefits of this pattern like modularity, reusability and testability for example.