Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellogalhardo committed Sep 7, 2021
1 parent b0bbdb3 commit e1f6267
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ dependencies {
To use `Whetstone` you must initialized it in your Application class.

```kotlin
class MyApplication : Application() {
class MyApplication : Application(), ApplicationComponentOwner {

fun onCreate() {
Whetstone.initialize { DaggerGeneratedApplicationComponent.factory().create(this) }
super.onCreate()
val applicationComponent by lazy {
DaggerGeneratedApplicationComponent.factory().create(this)
}
}
```
Expand All @@ -60,13 +59,16 @@ Component lifetimes are generally bounded by the creation and destruction of a c

```kotlin
@ContributesInjector(ApplicationScope::class)
class MyApplication: Application() {
class MyApplication: Application(), ApplicationComponentOwner {

val applicationComponent by lazy {
TODO("Create application component.")
}

@Inject
public lateinit var dependency: MyDependency

fun onCreate() {
Whetstone.initialize { TODO("Create root component") }
Whetstone.inject(application = this)
super.onCreate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.fragment.app.FragmentFactory
import androidx.lifecycle.Lifecycle
import com.deliveryhero.whetstone.component.ActivityComponent
import com.deliveryhero.whetstone.component.ApplicationComponent
import com.deliveryhero.whetstone.component.ApplicationComponentOwner
import com.deliveryhero.whetstone.injector.AnvilInjector
import com.deliveryhero.whetstone.injector.ContributesInjector
import java.util.concurrent.atomic.AtomicReference
Expand All @@ -26,7 +27,10 @@ public object Whetstone {
}

public fun <T : Any> fromApplication(application: Application): T {
return requireNotNull(root.get()) { "Whetstone must be initialized to be used." } as T
require(application is ApplicationComponentOwner) {
"Application must implement ${ApplicationComponentOwner::class.java.name} to use this Injector"
}
return application.applicationComponent as T
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.deliveryhero.whetstone.component

public interface ApplicationComponentOwner {

public val applicationComponent: ApplicationComponent
}

This file was deleted.

0 comments on commit e1f6267

Please sign in to comment.