Arrow--轻量级的Android DI 库

来源:互联网 发布:手游直播下什么软件 编辑:程序博客网 时间:2024/06/05 20:15

Arrow 是一个轻量级的Android DI 库,没有额外的引用。

为什么

最流行的Android DI框架中,Roboguice已经不再维护了,Dagger2使用有点复杂,需要写component interface(所以我写了一个自动生成component interface的库Dagger2Plus),而且Dagger2使用代码生成,对于有代码洁癖的人来说不太喜欢。Arrow使用反射,在目前动不动就8核10核2G3G的硬件环境下,反射带来的性能缺陷不再明显,作为个人来说还是能接受的。

特性

1、@Inject
对象注入

2、@Singleton
单例对象注入

3、Provider 接口
处理循环依赖
例如:

public class A {    final B b;    @Inject    public A(B b) {        this.b = b;    }    public String print() {        return "I am A";    }}public class B {    Provider<A> a;    @Inject    public B(Provider<A> a) {        this.a = a;    }}

4、Application注入
后续加入各种Service Manager的注入

5、@OnClick
View点击事件处理

6、@ContentView
支持Activity和Fragment setContentView

7、@OnPostInject
Inject 结束后触发该函数

8、@InjectExtra
支持Activity和Fragment 注入Bundle

Arrow+DataBinding

使用DataBinding替代butterknife
Object的注入使用Arrow

源代码

https://github.com/MasonLiuChn/Arrow

用法

repositories {    maven {        url "https://jitpack.io"    }}dependencies {    compile 'com.github.MasonLiuChn:Arrow:1.0.0'}
Arrow.init(Application application);Arrow.inject(Object object);Arrow.injectContentView(Object fragment, LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)

其他

之前一直有个做App热更新的想法,是基于DroidPlugin是的全量插件化,最近终于有时间把代码写好了,见另一篇文章FullPlugin

Contact me:

  • Blog:http://www.masonliu.com

  • Email:MasonLiuChn@gmail.com

0 0
原创粉丝点击