mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 05:57:03 +05:30
feat(di): kick off Anvil infra
This commit is contained in:
parent
3c0a8dd392
commit
ce37903ea0
6 changed files with 99 additions and 0 deletions
22
core/build.gradle.kts
Normal file
22
core/build.gradle.kts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright © 2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
@file:Suppress("DSL_SCOPE_VIOLATION", "UnstableApiUsage")
|
||||
|
||||
plugins {
|
||||
kotlin("android")
|
||||
id("dev.msfjarvis.claw.kotlin-common")
|
||||
id("dev.msfjarvis.claw.android-library")
|
||||
alias(libs.plugins.anvil)
|
||||
}
|
||||
|
||||
android { namespace = "dev.msfjarvis.claw.core" }
|
||||
|
||||
dependencies {
|
||||
implementation(projects.diScopes)
|
||||
implementation(libs.dagger)
|
||||
implementation(libs.javax.inject)
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright © 2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.core.injection
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import com.squareup.anvil.annotations.ContributesTo
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dev.msfjarvis.claw.injection.scopes.AppScope
|
||||
|
||||
@Module
|
||||
@ContributesTo(AppScope::class)
|
||||
interface ContextModule {
|
||||
@get:Binds val Application.bindContext: Context
|
||||
}
|
18
di-scopes/build.gradle.kts
Normal file
18
di-scopes/build.gradle.kts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright © 2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
@file:Suppress("DSL_SCOPE_VIOLATION", "UnstableApiUsage")
|
||||
|
||||
plugins {
|
||||
kotlin("jvm")
|
||||
id("dev.msfjarvis.claw.kotlin-library")
|
||||
alias(libs.plugins.anvil)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.dagger)
|
||||
implementation(libs.javax.inject)
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright © 2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.injection
|
||||
|
||||
object Components {
|
||||
|
||||
@PublishedApi @Suppress("ObjectPropertyName") internal val _components = mutableSetOf<Any>()
|
||||
|
||||
fun add(component: Any) {
|
||||
_components.add(component)
|
||||
}
|
||||
|
||||
inline fun <reified T> get(): T = _components.filterIsInstance<T>().single()
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright © 2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.injection.scopes
|
||||
|
||||
abstract class AppScope private constructor()
|
|
@ -0,0 +1,12 @@
|
|||
/*
|
||||
* Copyright © 2022 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.injection.scopes
|
||||
|
||||
import javax.inject.Scope
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Scope @Retention(AnnotationRetention.RUNTIME) annotation class SingleIn(val clazz: KClass<*>)
|
Loading…
Add table
Add a link
Reference in a new issue