0Pricing
Jetpack Compose Academy · Ders

DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod

Hilt'in çözdüğü sorunları görün.

DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod, CoddyKit'te ücretsiz bir Jetpack Compose Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Jetpack Compose Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What Is Dependency Injection?

Dependency injection means a class receives the objects it needs from the outside, instead of building them itself. Less wiring, more focus. 🔌

The Problem: new Everywhere

When a class calls new on its own dependencies, it gets locked to those exact types. Changing one thing forces you to edit many files.

class Repo {
    private val api = ApiService() // hard-wired
}

Inject Instead of Construct

Pass dependencies through the constructor and let something else create them. Now your class only states what it needs, not how to build it.

class Repo(private val api: ApiService) {
    // api is given to us
}

Decoupling Made Real

With injection your code depends on an interface, not a concrete class. You can swap the real one for another without touching the consumer.

interface ApiService { fun load(): String }
class Repo(private val api: ApiService)

Testability Is the Big Win

In tests you simply pass a fake dependency. No network, no database, no surprises, just fast and predictable checks. ✅

val fake = object : ApiService { override fun load() = "hi" }
val repo = Repo(fake)

Manual DI Gets Tedious

You can inject by hand, but wiring deep graphs means writing lots of boilerplate. Every new dependency ripples up through the constructors.

val api = ApiService()
val repo = Repo(api)
val vm = MyViewModel(repo) // by hand

Enter Hilt

Hilt is Android's recommended DI library. It generates the wiring for you at compile time, so you describe needs and Hilt builds the graph.

Hilt Sits on Top of Dagger

Hilt is built on Dagger but adds Android-aware defaults. You get compile-time safety with far less setup than raw Dagger.

Mark Your Application

Hilt starts at the app root. Annotate your Application class with @HiltAndroidApp to generate the top-level dependency container.

@HiltAndroidApp
class MyApp : Application()

Inject With @Inject

Add @Inject to a constructor and Hilt learns how to create that type. From then on it can supply it anywhere it is needed.

class Repo @Inject constructor(private val api: ApiService)

Compile-Time Safety

If a dependency is missing, Hilt fails at compile time, not at runtime. You catch wiring mistakes before the app ever ships. 🛡️

Quick Check

Which benefit best captures why we use dependency injection?

Recap: Why DI Matters

You learned that DI hands a class its dependencies, decoupling code and making tests trivial. Hilt automates that wiring at compile time. 🎉

Sıkça Sorulan Sorular

“DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod” dersi ücretsiz mi?

Evet — “DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Jetpack Compose Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Jetpack Compose Academy kursu toplamda 4 dersten oluşur.

“DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod” dersinde ne öğreneceğim?

Hilt'in çözdüğü sorunları görün. Jetpack Compose Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Jetpack Compose Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Jetpack Compose Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Jetpack Compose Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Jetpack Compose Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. DI Neden Kullanılır: Test Edilebilir, Ayrıştırılmış Kod
  2. Modüller, @Provides ve @Binds
  3. hiltViewModel ve @HiltViewModel
  4. Kapsamlar ve Bileşen Ömürleri
← Jetpack Compose Academy Sayfasına Dön