question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduction of a Dependency Injection Framework

See original GitHub issue

Current 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:closed
  • Created 3 years ago
  • Reactions:21
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
timo-drickcommented, Jun 1, 2020

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.

8reactions
svenjacobscommented, Jun 2, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found