This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.example.testdi"> | |
<application | |
android:name="com.example.testdi.MyApp" | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:roundIcon="@mipmap/ic_launcher_round" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.app.Application | |
import com.example.testdi.di.appDependencies | |
import org.koin.android.ext.koin.androidContext | |
import org.koin.android.ext.koin.androidLogger | |
import org.koin.core.context.startKoin | |
class MyApp : Application() { | |
override fun onCreate() { | |
super.onCreate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.example.testdi.storage.FakeInMemoryUsersRepository | |
import com.example.testdi.storage.IUsersRepository | |
import org.koin.dsl.module | |
val appDependencies = module { | |
// Singleton (returns always the same unique instance of the object) | |
single<IUsersRepository> { FakeInMemoryUsersRepository() } | |
// Transient (returns always the a new instance of the object) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val usersRepository: IUsersRepository by inject() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation "org.koin:koin-android:$koin_version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ext.koin_version = "2.1.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.appcompat.app.AppCompatActivity | |
import android.os.Bundle | |
import com.example.testdi.domain.User | |
import com.example.testdi.storage.IUsersRepository | |
import java.text.SimpleDateFormat | |
class MainActivity : AppCompatActivity() { | |
private val dateFormat: SimpleDateFormat = SimpleDateFormat("dd/MM/yyyy") | |
private val usersRepository: IUsersRepository // Will compile in the next snippet :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Log | |
import com.example.testdi.domain.User | |
import java.text.SimpleDateFormat | |
class FakeInMemoryUsersRepository : IUsersRepository { | |
override fun getById(userId: Int): User { | |
return User( | |
"fbonizzi", | |
"Francesco", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IUsersRepository { | |
fun getById(userId : Int) : User | |
fun save(user: User) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.* | |
data class User( | |
val UserId : String, | |
val Name : String, | |
val Surname : String, | |
val BirthDate : Date | |
) |