Skip to content

Commit 6ab68c0

Browse files
committed
Minor adjustments and wording updates
Signed-off-by: David Kral <[email protected]>
1 parent feac872 commit 6ab68c0

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

docs/src/main/asciidoc/se/injection.adoc

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ Let's begin by explaining some basic terms.
7171
7272
== Basic terms
7373
74+
=== Dependency Injection
75+
Injection is a way to automatically provide instances of dependencies without having to create them manually.
76+
Instead of a class creating an object itself,
77+
something else (like a <<Service registry,service registry>>) hands it over when needed.
78+
This makes code cleaner, easier to manage, and more flexible.
79+
80+
For example, if a Car needs an Engine, instead of the Car making an Engine itself, it just asks for one,
81+
and the system provides it.
82+
This is called Dependency Injection (DI).
83+
7484
=== Declarative style of programming
7585
In a declarative approach, you use annotations on classes, constructors, and constructor arguments to express your intent.
7686
@@ -135,6 +145,9 @@ Services are defined by:
135145
1. Java classes annotated with one of the `Service.Scope` annotations (see <<Scopes, Scopes>>)
136146
2. Any class with `@Service.Inject` annotation even when it doesn’t have a scope annotation. In such a case, the scope of the service will be set as `@Service.PerLookup`.
137147
148+
Keep in mind that if you create any service instance directly, it will not get its injection points resolved!
149+
This works only when using service registry.
150+
138151
Now, let's talk about an injection points.
139152
140153
== Injection points
@@ -167,7 +180,7 @@ Helidon Inject provides three built-in scopes:
167180
- `@Service.PerRequest` – A single instance per request exists in the service registry. The definition of a "request" is not enforced by the injection framework but aligns with concepts like an HTTP request-response cycle or message consumption in a messaging system.
168181
169182
== Build time
170-
To ensure everything functions correctly,
183+
To ensure everything works correctly,
171184
you need to add the following annotation processors to your application's compilation process.
172185
173186
These processors generate the necessary metadata and wiring for dependency injection and service registration in Helidon Inject.
@@ -232,7 +245,10 @@ to print out `Hello David!`. To find out more about this manual approach, please
232245
include::{sourcedir}/se/inject/BasicExample.java[tag=snippet_3, indent=0]
233246
----
234247
235-
If everything went as expected, no problems occurred and Service registry gave us fully initialized
248+
The last step is ensuring that everything necessary for your application to compile correctly with injection is included.
249+
See <<Build time,Build time>>.
250+
251+
If everything went as expected, no problems occurred and a Service registry gave us fully initialized
236252
and ready to use service.
237253
238254
== Service Lifecycle
@@ -443,8 +459,6 @@ The `@Interception.Delegate` annotation enables interception for classes
443459
that aren’t created through the service registry
444460
but are instead produced by a factory (More about factories can be found here -
445461
<<Factories, Factory chapter>>).
446-
To enable interception, this annotation must be present on the class that the factory produces.
447-
While it is not required on interfaces, it will still function correctly if applied there.
448462
449463
Let's make the same `@Traced` annotation and Interceptor as in the previous examples
450464
@@ -463,13 +477,17 @@ include::{sourcedir}/se/inject/InterceptorDelegateExample.java[tag=snippet_2, in
463477
----
464478
465479
Method calls on an instance created this way can’t be intercepted. To enable interception in such cases, we use the `@Interception.Delegate` annotation. However, keep in mind that usage of this annotation doesn’t add the ability to intercept constructor calls.
480+
To enable interception, this annotation must be present on the class that the factory produces.
481+
While it is not required on interfaces, it will still work correctly if applied there.
466482
467-
If you need to enable interception for classes using delegation, you should:
483+
If you need to enable interception for classes using delegation, you should make sure about the following:
468484
469485
- The class must have accessible no-arg constructor (at least package local)
470486
- The constructor should have no side effects, as the instance will act only as a wrapper for the delegate
471487
- All invoked methods must be accessible (at least package local)
472488
489+
Therefore using `@Interception.Delegate` on the classes can be considered as acknowledgement of the rules above.
490+
473491
[source,java]
474492
.Delegate used on the class
475493
----

0 commit comments

Comments
 (0)