猫猫注入框架! 无反射!使用Gradle Transform API实现的自动化依赖注入! 用了就会变可爱!!

Overview

CatInject

一个自动注入依赖的框架

导入

mavenCentral 版本: Maven Central
mavenCentral 发布需要一定时间, 如果发现最新版本不能用, 建议稍等4小时左右

  1. 在项目根 build.gradle:
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("io.github.zsqw123:cat-inject-plugin:$version")
    }
}
  1. 在需要用到注入的模块的 build.gradle:
plugins {
    id "cat-inject"
}

dependencies {
    implementation "io.github.zsqw123:cat-inject-lib:$version"
}

使用

在需要自动注入的接口上添加注解 @CatInject

@CatInject
interface IUser {
    fun getName(): String
    fun getAge(): Int
}

在任意位置(任意内外部依赖均可)实现这个接口:

class UserImpl : IUser {
    override fun getName(): String = "my-injected-user"
    override fun getAge(): Int = 1
}

class UserImpl2 : IUser {
    override fun getName(): String = "my-injected-user2"
    override fun getAge(): Int = 2
}

然后在导入了依赖的库里面就可以自动注入依赖了!

val randomUser = CatInjects.getInstance<IUser>() // 随便获取一个实例
val age2user = CatInjects.getAllInstances<IUser>() // 获取全部实例, 筛选所需实例
	.first { it.getAge() == 2 }

示例:zsqw123/CatInjectSample

Thanks

Gradle Transform + ASM 探索 (juejin.cn)

App流畅度优化:利用字节码插桩实现一个快速排查高耗时方法的工具

xiazunyang/discovery

bytedance/ByteX: 字节码插件开发平台

You might also like...
Releases(1.78)
Owner
Pour my all love out.
null
🌠 Transform into a different view or activity using morphing animations.

TransformationLayout ?? Transform into a different view or activity using morphing animations. Using Transformation motions of new material version. D

Jaewoong Eum 2k Jan 3, 2023
Transform java callback to kotlin suspend method.

Callback2Coroutines Transform Java callback to coroutines suspend method. 将传统Java callback 方法转换为kotlin中的suspend方法。 接入指南 根目录下加入jatpack的repository: allp

RainFool 14 May 25, 2021
Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension.

ViewBinding Delegate Extension Support extension to use Android ViewBinding quickly and smooth transform from kotlin-synthetic-extension. Binding inst

Cuong V. Nguyen 3 Dec 13, 2021
🔪 AOP development framework implemented through *Annotation + ASM + Gradle Transform API* for Android🤖

?? AOP development framework implemented through *Annotation + ASM + Gradle Transform API* for Android??

Pumpkin 325 Nov 22, 2022
Kafka Connect JSLT Single Message Transform

This is an implementation of the Kafka Connect SMT interface to offer transformation capabilities using the Schibsted JSLT library.

willhaben 2 May 25, 2022
Counterpart of onTouchEvent for Jetpack Compose and transform gesture with specific number of pointers

Counterpart of onTouchEvent for Jetpack Compose and transform gestures notify when last pointer is up number of pointer that are down or list of pointers that can be used to get details of events when gesture is on

Smart Tool Factory 19 Nov 19, 2022