-
Notifications
You must be signed in to change notification settings - Fork 17
/
2019-07-25-quarkus-dependency-injection.adoc.po
288 lines (249 loc) · 16.9 KB
/
2019-07-25-quarkus-dependency-injection.adoc.po
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# SOME DESCRIPTIVE TITLE
# Copyright (C) YEAR Free Software Foundation, Inc.
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2022-05-12 15:52+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: zh_CN\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#. type: Title =
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Quarkus Dependency Injection"
msgstr "Quarkus依赖性注入"
#. type: YAML Front Matter: synopsis
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Quarkus ArC is a build-time oriented dependency injection based on CDI 2.0. But what does it actually mean and what benefits does a build-time processing DI bring?"
msgstr "Quarkus ArC是一个基于CDI 2.0的面向构建时的依赖注入。但它实际上意味着什么,构建时处理的DI会带来什么好处?"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"Quarkus ArC is a build-time oriented dependency injection based on http://cdi-spec.org/[CDI 2.0].\n"
"In this blogpost, we're going to explain the relationship to the specification and describe some of the benefits and drawbacks of the build-time processing design."
msgstr "Quarkus ArC 是基于 link:http://cdi-spec.org/[CDI 2.0 的] 面向构建时间的依赖注入。在这篇博文中,我们将解释与规范之间的关系,并介绍构建时处理设计的一些优点和缺点。"
#. type: Title ==
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, no-wrap
msgid "Compatibility"
msgstr "兼容"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"It does not make sense to reinvent the wheel, especially when it comes to dependency injection.\n"
"There are many frameworks that try to solve similar problems.\n"
"A year ago, we made a design decision to build Quarkus DI on top of CDI.\n"
"We had some very good reasons to choose CDI:"
msgstr "重新发明轮子是没有意义的,尤其是在依赖注入方面。有很多框架都试图解决类似的问题。一年前,我们做出了在 CDI 基础上构建 Quarkus DI 的设计决定。我们有充分的理由选择 CDI:"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "CDI is a mature and proven component model"
msgstr "CDI是一个成熟的、经过验证的组件模型"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "We at Red Hat have almost ten years of experience with developing http://weld.cdi-spec.org/[Weld - the CDI Reference Implementation]"
msgstr "我们红帽公司在开发 link:http://weld.cdi-spec.org/[Weld] 方面有近十年的经验 link:http://weld.cdi-spec.org/[--CDI参考实现。]"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "The CDI API is built on top of `javax.inject` so that it should be easy to migrate from any DI framework compatible with `@Inject`"
msgstr "CDI API是建立在 `javax.inject` 的基础上的,所以它应该很容易从任何兼容DI框架中迁移出来。 `@Inject` "
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"Our primary goal was to implement a supersonic build-time oriented DI solution compatible with CDI.\n"
"This would allow users to continue using CDI in their applications but also leverage Quarkus build-time optimizations.\n"
"However, ArC is not a full CDI implementation verified by the TCK - see also the list of https://quarkus.io/guides/cdi-reference#supported_features[supported features] and the list of https://quarkus.io/guides/cdi-reference#limitations[limitations]."
msgstr "我们的主要目标是实现与 CDI 兼容的超音速构建时间导向 DI 解决方案。这将允许用户在其应用程序中继续使用 CDI,同时还能利用 Quarkus 的构建时间优化功能。不过,ArC 并不是经过 TCK 验证的完整 CDI 实现,请参见 link:https://quarkus.io/guides/cdi-reference#supported_features[支持功能] 列表和 link:https://quarkus.io/guides/cdi-reference#limitations[限制] 列表。"
#. type: Title ==
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Build-time Processing Benefits and Drawbacks"
msgstr "构建时间处理的好处和坏处"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Fail Fast"
msgstr "快速失败"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "Beans and dependencies are validated during the build so that your application can never fail in production with common problems such as `AmbiguousResolutionException` or `UnsatisfiedResolutionException`."
msgstr "在构建过程中对Bean和依赖关系进行了验证,这样你的应用程序就不会在生产中出现常见问题,如 `AmbiguousResolutionException` 或 `UnsatisfiedResolutionException` 。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Instant Startup"
msgstr "即时启动"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"When the app starts ArC just loads all the metadata and initializes some internal structures.\n"
"There is no need to analyze the application classes again.\n"
"This means negligible startup overhead."
msgstr "应用程序启动时,ArC 只需加载所有元数据并初始化一些内部结构。无需再次分析应用程序类。这意味着可忽略不计的启动开销。"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "This applies to both the GraalVM and OpenJDK HotSpot runtimes."
msgstr "这同时适用于GraalVM和OpenJDK HotSpot运行系统。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Minimized Runtime"
msgstr "最小化的运行时间"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"In Quarkus 0.19, ArC plus integration runtime consist of 72 classes and occupies ~ 140 KB in jars.\n"
"http://weld.cdi-spec.org/[Weld 3.1.1] (CDI Reference Implementation) core is roughly 1200 classes and approx. 2 MB jar.\n"
"In other words, ArC runtime takes approx. 7% of the Weld runtime in terms of number of classes and jar footprint."
msgstr "在 Quarkus 0.19 中,ArC 加集成运行时由 72 个类组成,占大约 140 KB 的 jar。 link:http://weld.cdi-spec.org/[Weld 3.1.1] (CDI 参考实现)核心大约有 1200 个类,jar 大约有 2 MB。换句话说,就类的数量和 jar 占用空间而言,ArC 运行时约占 Weld 运行时的 7%。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Optimized Code Paths and Metadata Structures"
msgstr "优化的代码路径和元数据结构"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"When generating the metadata classes ArC can sometimes produce leaner and smarter logic because it has the whole application analyzed already.\n"
"This is one of the areas where we would like to develop and improve ArC."
msgstr "在生成元数据类时,ArC 有时可以生成更精简、更智能的逻辑,因为它已经对整个应用程序进行了分析。这是我们希望开发和改进 ArC 的领域之一。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Extension Points"
msgstr "扩展点"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"Unfortunately, CDI portable extensions are inherently runtime constructs and therefore cannot be fully supported in Quarkus.\n"
"In fact, all CDI extensions are ignored at the moment.\n"
"Nevertheless, most of the functionality can be achieved using https://quarkus.io/guides/cdi-reference#build-time-extension-points[Quarkus extensions].\n"
"The CDI extensions are encouraged to generalize the code, and if possible provide a Quarkus extension to make full use of build-time metadata processing."
msgstr "遗憾的是,CDI 可移植扩展本身就是运行时构造,因此 Quarkus 无法完全支持。事实上,目前所有 CDI 扩展都被忽略。不过, link:https://quarkus.io/guides/cdi-reference#build-time-extension-points[Quarkus 扩展] 可以实现大部分功能。我们鼓励 CDI 扩展将代码通用化,并在可能的情况下提供 Quarkus 扩展,以充分利用构建时元数据处理功能。"
#. type: Title ==
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, no-wrap
msgid "Non-standard Features"
msgstr "非标准功能"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"ArC is not limited to standards and we're constantly looking for ways to go beyond and extend the possibilities.\n"
"Following are some examples of non-standard features provided by Quarkus DI."
msgstr "ArC 并不局限于标准,我们一直在寻找超越和扩展可能性的方法。以下是 Quarkus DI 提供的一些非标准功能示例。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Qualified Injected Fields"
msgstr "合格的注射场"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "Normally, if you declare an injected field you'll always need to use `@Inject` and optionally required qualifiers:"
msgstr "通常情况下,如果你声明一个注入的字段,你总是需要使用 `@Inject` 和可选的必要限定词。"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "In Quarkus, you can skip the `@Inject` annotation completely if an injected field declares at least one qualifier:"
msgstr "在Quarkus中,如果一个注入的字段至少声明了一个限定词,你可以完全跳过 `@Inject` 注释。"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "`@Inject` is still required for constructor and method injection."
msgstr " `@Inject` 仍然需要构造函数和方法注入。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Simplified Constructor Injection"
msgstr "简化的构造函数注入"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"In CDI, a normal scoped bean must always declare a no-args constructor (this constructor is normally generated by the compiler unless you declare any other constructor).\n"
"However, this requirement complicates constructor injection - you would need to provide a dummy no-args constructor to make things work in CDI."
msgstr "在 CDI 中,普通作用域 Bean 必须始终声明一个无参数构造函数(该构造函数通常由编译器生成,除非您声明任何其他构造函数)。然而,这一要求使构造函数注入变得复杂--您需要提供一个虚假的无参数构造函数,才能在 CDI 中正常工作。"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"There is no need to declare dummy constructors for normal scoped bean in Quarkus - they are generated automatically.\n"
"Also if there's only one constructor there is no need for `@Inject`."
msgstr "在 Quarkus 中,无需为普通作用域 Bean 声明虚拟构造函数,它们会自动生成。此外,如果只有一个构造函数,就不需要 `@Inject` 。"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "We don't generate a no-args constructor automatically if a bean class extends another class that does not declare a no-args constructor."
msgstr "如果一个Bean类扩展了另一个没有声明no-args构造函数的类,我们不会自动生成no-args构造函数。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Default Beans"
msgstr "默认豆类"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"CDI has a feature called https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#alternatives[alternatives].\n"
"Simply said a bean annotated with `@Alternative` and `@Priority` takes precedence over the non-alternative beans during type-safe resolution."
msgstr "CDI 有一个称为 link:https://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#alternatives[替代的] 功能。简单地说,在类型安全解析过程中,注释为 `@Alternative` 和 `@Priority` 的 Bean 优先于非替代 Bean。"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"So, what if a user wants to override a bean defined by a library/extension?\n"
"The bean would have to be marked as a CDI `@Alternative` that is enabled using the `@Priority` annotation.\n"
"Is there a simpler approach?\n"
"Yes, there is.\n"
"You can use a non-standard feature called \"default beans\".\n"
"In this case, a bean that can be overridden should be annotated with `@io.quarkus.arc.DefaultBean`.\n"
"And that's it."
msgstr "那么,如果用户想要覆盖由库/扩展定义的 Bean,该怎么办呢?该 Bean 必须标记为 CDI `@Alternative` ,并使用 `@Priority` 注解启用。有没有更简单的方法?有。您可以使用一种称为 \"默认 Bean \"的非标准功能。在这种情况下,可以重写的 bean 应使用 `@io.quarkus.arc.DefaultBean` 注释。就是这样。"
#. type: Title ===
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy, no-wrap
msgid "Removing Unused Beans"
msgstr "移除未使用的豆子"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"GraalVM native image does a pretty good job when removing all classes that are not reachable from your application.\n"
"However, sometimes checking reachability is not enough.\n"
"Sometimes the framework itself must decide whether a component is needed or not.\n"
"In standard CDI, all beans are retained by the container no matter whether they're needed or not."
msgstr "GraalVM 本地镜像可以很好地移除应用程序中所有无法访问的类。不过,有时仅检查可达性是不够的。有时,框架本身必须决定是否需要某个组件。在标准 CDI 中,无论是否需要,容器都会保留所有 Bean。"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"Let's suppose we have a bean class `org.acme.Foo`.\n"
"This bean class imports and uses a lot of various classes.\n"
"It's annotated with `@ApplicationScoped` and so Quarkus needs to generate a bean metadata class and a client proxy and register this metadata when the application starts.\n"
"But what if nobody ever uses this bean?\n"
"We would still hold a reference on the generated metadata, and the bean class itself, and its dependencies.\n"
"In other words, all these classes would be reachable."
msgstr "假设我们有一个 Bean 类 `org.acme.Foo` 。这个 Bean 类导入并使用了大量不同的类。它被注释为 `@ApplicationScoped` ,因此 Quarkus 需要生成一个 Bean 元数据类和一个客户端代理,并在应用程序启动时注册这些元数据。但是,如果从来没有人使用过这个 Bean 呢?我们仍将保留对生成的元数据、Bean 类本身及其依赖关系的引用。换句话说,所有这些类都是可以访问的。"
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid ""
"Quarkus attempts to remove all *unused beans* during build by default.\n"
"This helps to reduce the number of generated classes and also the amount of memory needed at runtime.\n"
"But how do we actually detect an unused bean?\n"
"The rules are described in the https://quarkus.io/guides/cdi-reference#remove_unused_beans[reference guide] but simply said: if a bean is not injected anywhere and cannot be reached in any other standard way (e.g. observer notification) it is removed.\n"
"Moreover, users can instruct the container to not remove a bean by annotating the bean class with `@io.quarkus.arc.Unremovable`.\n"
"Finally, this optimization can be disabled and fine tuned by using the `quarkus.arc.remove-unused-beans` property."
msgstr "默认情况下,Quarkus 会在构建过程中移除所有 *未使用的 Bean* 。这有助于减少生成类的数量和运行时所需的内存量。但我们究竟该如何检测未使用的 Bean 呢? link:https://quarkus.io/guides/cdi-reference#remove_unused_beans[参考指南] 中描述了相关规则,但简单地说:如果某个 Bean 没有被注入到任何地方,并且无法通过任何其他标准方式(如观察者通知)到达,那么该 Bean 就会被移除。此外,用户可以通过用 `@io.quarkus.arc.Unremovable` 注释 bean 类来指示容器不要删除 bean。最后,可以通过使用 `quarkus.arc.remove-unused-beans` 属性来禁用和微调这种优化。"
#. type: Plain text
#: _posts/2019-07-25-quarkus-dependency-injection.adoc
#, fuzzy
msgid "This feature applies to the JVM mode as well."
msgstr "这一功能也适用于 JVM 模式。"