Skip to content

Instantly share code, notes, and snippets.

View AlirezaNezami96's full-sized avatar
🌏
Looking for remote or relocation job

Alireza Nezami AlirezaNezami96

🌏
Looking for remote or relocation job
  • Tabriz, Iran
View GitHub Profile
@AlirezaNezami96
AlirezaNezami96 / DependencyComponent .kt
Created September 29, 2021 08:46
This class provides the dependencies that classes want to function
object DependencyComponent {
fun inject(application: MyApplication) {
application.networkService = NetworkService(application, "SOME_API_KEY")
application.databaseService = DatabaseService(application, "dummy_db", 1)
}
fun inject(activity: MainActivity) {
val app = activity.application as MyApplication
activity.viewModel = MainViewModel(app.databaseService, app.networkService)
}
@AlirezaNezami96
AlirezaNezami96 / MyApplication.kt
Last active September 29, 2021 08:37
create DatabaseService and NetworkService when onCreate method called
class MyApplication : Application() {
var networkService: NetworkService? = null
var databaseService: DatabaseService? = null
override fun onCreate() {
super.onCreate()
networkService = NetworkService(this, "SOME_API_KEY")
databaseService = DatabaseService(this, "dummy_db", 1)
}
}