ੑ ࢎਊೞӝ Navigating Dependency Injection with Metro (by Zac Sweers) HyunWoo Lee Kotlin User Groups Seoul Organizer GDG Korea Android Organizer Viva Reupublica(Toss) Android/React Native Developer
Engineer Community & Open Source Lover - GDG Korea Android, Kotlin User Groups Seoul - Contributer & Maintainer Making a new frontier of React Native X Android Granite ❤ Apps In Toss ❤
run(location: String) { val service = WeatherService() val formatter = WeatherFormatter() val forecast = service.getForecast(location) println(formatter.format(forecast)) } }
service: WeatherService private val formatter: WeatherFormatter ) { / / . . . } fun main() { val httpClient = HttpClient() val service = WeatherService(httpClient) val formatter = WeatherFormatter() val app = WeatherApp(service, app) }
service: WeatherService private val formatter: WeatherFormatter ) { / / . . . } fun main() { val cache = Cache() val httpClient = HttpClient(cache) val service = WeatherService(httpClient) val formatter = WeatherFormatter() val app = WeatherApp(service, app) }
Cache) class WeatherService(private val httpClient: HttpClient) class WeatherFormatter(…) class WeatherApp( private val service: WeatherService private val formatter: WeatherFormatter ) fun main() { val cache = Cache() val httpClient = HttpClient(cache) val service = WeatherService(httpClient) val formatter = WeatherFormatter() val app = WeatherApp(service, app) } ࣻز ੑ
val cache: Cache) class WeatherService(private val httpClient: HttpClient) class WeatherFormatter(…) class WeatherApp( private val service: WeatherService private val formatter: WeatherFormatter )
class HttpClient(private val cache: Cache) @Inject class WeatherService(private val httpClient: HttpClient) @Inject class WeatherFormatter(…) @Inject class WeatherApp( private val service: WeatherService private val formatter: WeatherFormatter )
cache = Cache() val httpClient = HttpClient() val service = WeatherService(httpClient) val formatter = WeatherFormatter() val app = WeatherApp(service, formatter) }
class HttpClient( private val cache: Cache ) @Inject class WeatherService( private val httpClient: HttpClient ) @Inject class WeatherFormatter @Inject class WeatherApp( private val service: WeatherService private val formatter: WeatherFormatter ) @DependencyGraph interface AppGraph { val app: WeatherApp } fun main() { val app = createGraph<AppGraph>().app }
class WeatherService( private val httpClient: HttpClient ) @Inject class WeatherApp( private val service: WeatherService private val formatter: WeatherFormatter ) @DependencyGraph interface AppGraph { val app: WeatherApp } Always same instance
declare instead Scope annotations Aggregation scopes Provider/Binds callables Their own extensions! @GraphExtension interface LoggedInActivityGraph { val user: User val activity: Activity } @GraphExtension interface LoggedInGraph { val user: User val loggedInActivityGraph: LoggedInActivityGraph } @DependencyGraph interface AppGraph { val loggedInGraph: LoggedInGraph }
f i les Kapt (javac) Kapt source f i les kotlinc (Frontend and Backend) compileKotlin .class f i les javac compileJava More .class f i les KAPTܳ ࢎਊೠݶ?
f i les Kapt (javac) Kapt source f i les kotlinc (Frontend and Backend) compileKotlin .class f i les javac compileJava More .class f i les HILT ࠽٘ ۄੋ javac :hiltJavaCompileDebug Even more .class f i les
f i les Kapt (javac) Kapt source f i les kotlinc (Frontend and Backend) compileKotlin .class f i les javac compileJava More .class f i les HILT ࠽٘ ۄੋ javac :hiltJavaCompileDebug Even more .class f i les