feat(di): kick off Anvil infra

This commit is contained in:
Harsh Shandilya 2022-11-13 13:13:03 +05:30
parent 3c0a8dd392
commit ce37903ea0
No known key found for this signature in database
6 changed files with 99 additions and 0 deletions

22
core/build.gradle.kts Normal file
View 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)
}

View file

@ -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
}

View 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)
}

View 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.
*/
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()
}

View file

@ -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()

View file

@ -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<*>)