Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
Add examples to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
daugeldauge committed Sep 19, 2021
1 parent 16dd6b2 commit 43918b9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,57 @@ It's a [russian word](https://en.wiktionary.org/wiki/кинжал) for dagger. Y
**Will this project become deprecated after Dagger releases [support for KSP and Multiplatform](https://github.com/google/dagger/issues/2349)?**

Probably. But we'll see

# Examples

```kotlin
@AppScope
@Component(modules = [
NetworkModule::class,
], dependencies = [
AppDependencies::class,
])
interface AppComponent {
fun createAuthPresenter(): AuthPresenter
}

interface AppDependencies {
val application: Application
}

@Scope
annotation class AppScope

class Application

@AppScope
class Database @Inject constructor(application: Application)

class AuthPresenter @Inject constructor(database: Database, lastFmApi: LastFmApi)

class HttpClient

interface LastFmApi

class LastFmKtorApi @Inject constructor(client: HttpClient) : LastFmApi

interface NetworkModule {
companion object {
@AppScope
fun provideHttpClient() = HttpClient()
}

fun bindLastFm(lastFmApi: LastFmKtorApi): LastFmApi
}

// somewhere in your app
val component = KinzhalAppComponent(object : AppDependencies {
override val application = Application()
})

val presenter = component.createAuthPresenter()
```
See more in the [source code](https://github.com/daugeldauge/kinzhal/tree/master/sample/src/commonMain/kotlin/com/daugeldauge/kinzhal/sample/graph)

# Dagger2 compatibility table

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.daugeldauge.kinzhal.sample.graph

import com.daugeldauge.kinzhal.annotations.Component
import com.daugeldauge.kinzhal.sample.graph.network.HttpClientScope
import com.daugeldauge.kinzhal.sample.graph.network.*
import com.daugeldauge.kinzhal.sample.graph.network.NetworkModule

interface SuperComponent {
Expand Down

0 comments on commit 43918b9

Please sign in to comment.