Android + Hilt: Which classes should I inject which not?

Viewed 29

There's one concept that's difficult to catch for me regarding DI: Why should I inject this class and not this other one?

My problem arises in concrete with helper classes.

I'm working on a multi-module Android app and using Hilt for DI, and my app has many helper classes which I'm continuously doubting wether to inject them where necessary, or just create an instance.

To give some concrete examples:

  1. A class TMHttp with an "DownloadFile" or "IsOnline" methods (among others).
  2. A TMEmail class with a "SendEmail" method.
  3. A ImageHelper class with a "TakeScreenshot" or "CropBitmap" methods.
  4. TMImport/TMExport classes with "ImportData" and "ExportData" methods.
  5. A TMSession class with "LoginUser", "LogoutUser" and more such methods.
  6. A TMUtils class with methods like "GenerateRandom".
  7. A TMDialog class with methods like "CreateYesNoDialog" ... and many more.

I know there are no strict rules for everything in software developing, but anyway I need help with some general rule about why should I inject a class and not another one.

0 Answers
Related