Google Tiger

原文地址https://github.com/google/tiger

Description 描述

No description or website provided.
沒有提供描述或者網(wǎng)站

DISCLAIMER 免責(zé)聲明

DISCLAIMER: This is not an official Google product. Google's production dependency injection frameworks are Dagger and Guice.
免責(zé)聲明:這不是Google官方項(xiàng)目.Google的項(xiàng)目依賴Dagger和Guice注入框架。

Tiger - The fastest java dependency injection framework

Tiger-最快速的java依賴注入框架

Acknowledge 致謝

Tiger is highly inspired by Dagger, Kudos to those great guys.
Tiger靈感來自于Dagger,Kudos大神的啟發(fā)

Challenge 挑戰(zhàn)

If you find a faster DI framework, let me know. I will drop the title as long as it is proved.
如果你發(fā)現(xiàn)了更快的DI框架,請(qǐng)告訴我茉唉。只要證明了更快勤讽,我將去掉標(biāo)題电爹。

Why Tiger? 為什么用Tiger?

It is the fastest! Not faster, but the fastest! I have tried it on a big project with ~200 modules.
他是最快的!沒有最快,只有更快!我嘗試了擁有兩百個(gè)模塊的大項(xiàng)目。
While it takes hundreds of milliseconds to instantiate Dagger components, on the same hardware,
it only takes a few milliseconds to instantiate Tiger injectors.
在相同硬件的情況下,實(shí)例化Dagger組件需要幾百毫秒桐腌,而實(shí)例化Tigger組件只需要幾毫秒。
Minimal amount of code to write therefore easy to maintain, if you need to maintain it at all.
如果你需要維護(hù)他們苟径,你可以使用最少代碼量寫入案站,使其跟容易維護(hù)。
You don't need to write components like in Dagger.
你不需要跟Dagger一樣寫組件棘街。
You don't need to split a module into several modules one for each scope that used by bindings provided by the module.
你不需要為了使用某個(gè)模塊提供的綁定而去把一個(gè)模塊分隔成多個(gè)模塊蟆盐,
You will feel it is some easy to change the scope of a binding.
你會(huì)覺得很容易的去改變綁定的范圍
Just change it. Way to go, isn’t it?
想要改變它,就應(yīng)該這么做遭殉,不是嗎石挂?

Build up your knowledge 積累你的知識(shí)

If you are here, you must already be familiar with DI(Dependency Injection) and its advantage.
如果你讀到這里,你必須熟悉DI(依賴注入)及其優(yōu)勢险污。
Otherwise wiki will be your friend. DI has been evolving for long time in the different form.
不然wiki將會(huì)成為你的朋友痹愚。DI已在不同的結(jié)構(gòu)不斷的發(fā)展了很長一段時(shí)間。
But the concept is not really changed much. This document will not repeat these concepts.
但是他的概念沒有改變多少蛔糯。這個(gè)文檔不會(huì)重復(fù)這些概念拯腮。
If you find some concept not explained, google it. Also Guice probably has explained those concept very well.
如果你找到一些概念沒有解釋,請(qǐng)GOOGLE蚁飒。也許Guice可以更好的解釋這些概念疾瓮。

Integration 集成

Tiger is an annotation process.
Tiger是一個(gè)注釋進(jìn)程。
Therefore just build the jar and use it the way that annotation processors are supposed to be used.
因此在編譯Jar的時(shí)候注釋需要使用到它的方法飒箭。
All environment should work.
所有環(huán)境
The sample uses gradle.
例子使用gradle編譯

How? 怎么樣?

Before diving into details, it will be helpful, very helpful, to understand the intended usage of tiger.
在了解到細(xì)節(jié)之前蜒灰,它會(huì)對(duì)你有益弦蹂,非常的有幫助。讓你去明白Tiger的用途强窖。
Tiger is designed to let the machine do as much as possible and let human do as little as possible.
Tiger是設(shè)計(jì)的讓機(jī)器干更多的活凸椿,讓人盡可能的少干活。
It requires minimal information from the developer.
他只需要從開發(fā)者獲取很少的信息翅溺。
From these information, scoped injectors are generated.
從這些信息里面就可以產(chǎn)生范圍的注入器脑漫。
Application can instances these injectors and use them to inject classes.
應(yīng)用程序可以示例化這些注入器并且使用它們注入到類。
To achieve this, tiger has distilled the information needed to generate injectors.
為了實(shí)現(xiàn)這些咙崎,Tiger需要過濾這些信息來產(chǎn)生注入器优幸。
Here are they, with related annotation.
下面是它們和相關(guān)的注釋

Scopes使用范圍

Usually application has at least one scope, singleton.
通常應(yīng)用程序有一個(gè)作用域,單例褪猛。
Even if there is no scoped binding, it is harmless to have a singleton scope.
即使它沒有作用域綁定网杆,它只是一個(gè)單例的純凈作用域。
Therefore, tiger requires there always be a scope tree.
因此,Tiger需要有一些作用域的樹碳却。
The root is usually singleton, but not necessary.
根一般是單例队秩,但是不是必須的。
Details will be shown later in the sample.
在例子里面可以看到詳細(xì)的解釋
Tiger generates one injector class for each scope.
Tiger為每個(gè)作用域生成一個(gè)注入器昼浦。

@tiger.ScopeDependency

It specifies the dependencies between scopes.
他指定了作用域之間的依賴
All the dependency information form a scope tree.
所有的依賴信息形成一個(gè)作用樹

@tiger.Module

It provides binding information through @Provides annotated methods with optional scope.
他通過@Provides注釋方法可選作用域提供綁定信息馍资。
Now(2016/08/10) we just reuse dagger.Module.
現(xiàn)在(2016/08/10) 我們只是重用了Dagger.Module.
In future, dagger.Module will be copied into tiger.Module so that tiger does not need to depend on dagger.
未來,將把Dagger.Module將拷貝到Tiger.Module,使其不需要依賴Dagger.

@javax.inject.Inject on ctor

It provides binding information with optional scope.
它通過可選作用域提供綁定信息

@tiger.MembersInjector with mandatory scope

It specifies interfaces which includes class that has fields or methods to be injected.
它指定類的字段或者方法需要注入的接口
Injectors will implement all these interfaces.
注入器需要實(shí)現(xiàn)這些接口

@javax.inject.Inject on fields, methods

It specifies the injection points from which injector fans out when injecting an object.
它指定在向?qū)ο笞⑷霑r(shí)关噪,注入器的注入點(diǎn)鸟蟹。

@tiger.PackageForGenerated

The package for the generated injectors.
用于產(chǎn)生注入器的包。

@tiger.ScopedComponentNames

It specify the names of the injectors.
它提供了注入器的名字

@tiger.GenerationTriggerAnnotation

This the annotation that triggers the generation processor.
這是產(chǎn)生處理器的觸發(fā)器的注釋
@Module, @Inject and @MembersInjector are naturally scattered around the code.
For the others, i.e., @ScopeDependency, @PackageForGenerated, @ScopedComponentNames and @GenerationTriggerAnnotation, we suggest to put them into a dedicated java file as the central configuration information for the app.
關(guān)于其他的色洞,既@ScopeDependency, @PackageForGenerated, @ScopedComponentNames 和@GenerationTriggerAnnotation戏锹,我們建議把它們放在一個(gè)專門的java文件里面作為應(yīng)用程序的配置信息
Here is the depicted code the sample(with some modification)
這里是一些代碼端的例子(和一些改變)

@GenerationTriggerAnnotation
@PackageForGenerated("sample")
public class Scopes {
@ScopedComponentNames(scope = Singleton.class, name = "ApplicationInjector" )
public static class ForApplication {}
@ScopedComponentNames(scope = sample.ActivityScoped.class, name = "ActivityInjector" )
@ScopeDependency(scope = sample.ActivityScoped.class, parent = Singleton.class)
public static class ForActivityScoped {}
}

Here is how ApplicationInjector is instantiated and used.
這里是怎么樣去實(shí)例化和使用ApplicationInjector

ApplicationInjector applicationInjector = new ApplicationInjector.Builder().build();
PseudoApplication application = new PseudoApplication();
applicationInjector.injectPseudoApplication(application);
Here is how ActivityInjector is instantiated and used.
ActivityInjector activityInjector = new ActivityInjector.Builder()
.applicationInjector(applicationInjector)
.build();
activityInjector.injectPseudoActivity(this);

The injectors guarantee that scoped bindings will be instantiated at most once within a scope.
這個(gè)注入器保證了作用域類的綁定被實(shí)例化,一個(gè)作用域內(nèi)最多一個(gè)
The application needs to create related injectors for scope objects, e.g., in android, a context scoped injector for each Activity, a singleton scoped injector for the Application.
應(yīng)用程序需要為作用域?qū)ο髣?chuàng)建相關(guān)的注入器火诸,比如:在android里面锦针,每個(gè)Activity的context一個(gè)作用域注入器,在Application里面需要一個(gè)單例的作用域注入器置蜀。

Tip 貼士

Inspecting the generate code will help you. If you want more, there is source code. Enjoy injection!
檢查生成的代碼有助于你.如果你想要更多奈搜,這里有源代碼。享受注入吧

Group 組

fastesttiger@gmail.com
該轉(zhuǎn)載為了只是為了學(xué)習(xí)技術(shù)和英語所用盯荤,請(qǐng)勿用于其他用途

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末馋吗,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子秋秤,更是在濱河造成了極大的恐慌宏粤,老刑警劉巖,帶你破解...
    沈念sama閱讀 210,978評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件灼卢,死亡現(xiàn)場離奇詭異绍哎,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)鞋真,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,954評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門崇堰,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人涩咖,你說我怎么就攤上這事海诲。” “怎么了檩互?”我有些...
    開封第一講書人閱讀 156,623評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵特幔,是天一觀的道長。 經(jīng)常有香客問我闸昨,道長敬辣,這世上最難降的妖魔是什么雪标? 我笑而不...
    開封第一講書人閱讀 56,324評(píng)論 1 282
  • 正文 為了忘掉前任,我火速辦了婚禮溉跃,結(jié)果婚禮上村刨,老公的妹妹穿的比我還像新娘。我一直安慰自己撰茎,他們只是感情好嵌牺,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,390評(píng)論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著龄糊,像睡著了一般逆粹。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上炫惩,一...
    開封第一講書人閱讀 49,741評(píng)論 1 289
  • 那天僻弹,我揣著相機(jī)與錄音,去河邊找鬼他嚷。 笑死蹋绽,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的筋蓖。 我是一名探鬼主播卸耘,決...
    沈念sama閱讀 38,892評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼粘咖!你這毒婦竟也來了蚣抗?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,655評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤瓮下,失蹤者是張志新(化名)和其女友劉穎翰铡,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體讽坏,經(jīng)...
    沈念sama閱讀 44,104評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡两蟀,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,451評(píng)論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了震缭。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,569評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡战虏,死狀恐怖拣宰,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情烦感,我是刑警寧澤巡社,帶...
    沈念sama閱讀 34,254評(píng)論 4 328
  • 正文 年R本政府宣布,位于F島的核電站手趣,受9級(jí)特大地震影響晌该,放射性物質(zhì)發(fā)生泄漏肥荔。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,834評(píng)論 3 312
  • 文/蒙蒙 一朝群、第九天 我趴在偏房一處隱蔽的房頂上張望燕耿。 院中可真熱鬧,春花似錦姜胖、人聲如沸誉帅。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,725評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蚜锨。三九已至,卻和暖如春慢蜓,著一層夾襖步出監(jiān)牢的瞬間亚再,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,950評(píng)論 1 264
  • 我被黑心中介騙來泰國打工晨抡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留氛悬,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,260評(píng)論 2 360
  • 正文 我出身青樓凄诞,卻偏偏與公主長得像圆雁,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子帆谍,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,446評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容