-
Notifications
You must be signed in to change notification settings - Fork 564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.x: Introduction of Helidon Service Inject. #9249
Conversation
I have done a small update to include inject as a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LVGTM
Dmitry asked me to review. I mostly just had some questions and things to think about. I see there's an (enthusiastic) approval already so feel free to merge whenever you like; I don't want to get in the way.
Clearly a lot of work went into all this; hope this is useful. |
I will create follow up PRs that support |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple comments, aside from the offline review.
...ct/src/test/java/io/helidon/tests/integration/packaging/inject/InjectJarClassPathTestIT.java
Outdated
Show resolved
Hide resolved
5d8775c
to
47ae6f4
Compare
Added support for lookup tracing. Add the following to
|
Signed-off-by: Tomas Langer <[email protected]>
Signed-off-by: Tomas Langer <[email protected]>
Signed-off-by: Tomas Langer <[email protected]>
Signed-off-by: Tomas Langer <[email protected]>
Signed-off-by: Tomas Langer <[email protected]>
Proper qualifier for config beans even when `OrDefault` is used Added test for `OrDefault` Signed-off-by: Tomas Langer <[email protected]>
…annotations. Added feature processor and metadata codegen to Helidon Service Registry and Inject. Signed-off-by: Tomas Langer <[email protected]>
Add support for injection of InterceptionMetadata. Rework delegate interception to be usable by users.
…f possible. Changed default of Injection.Described to be singleton, as that feels more natural.
…ltiple constructor injection A few bugfixes for problems discovered by tests
…e for core registry) Introduction of ProviderType in descriptor and lookup, to distinguish contracts from provider handling. InterceptionMetadata moved to top level class.
- introduce inject codegen module - analysis/codegen separation Renaming of provider to Factory
Fix of inject packaging test - using the correct annotation processor.
61fed2a
to
8b2d87e
Compare
Rebased on latest |
Co-authored-by: Romain Grecourt <[email protected]>
Auto add contract interfaces is now default
Related to #9158 (Step 1)
Follow up steps:
javax
andjakarta
packages)Updated description (matches current PR state):
Inject Service Registry
An extension to the core service registry, Helidon Service Inject adds a few concepts:
Singleton
scope, optionalPerRequest
scope and possible custom scopesThe main entry point to get service registry is
io.helidon.service.inject.InjectRegistryManager
(part of implementation, not API), which can be used to obtainio.helidon.service.inject.api.InjectRegistry
.The registry can then be used to lookup services (it extends the existing
ServiceRegistry
).Injection and scopes
Annotation type:
io.helidon.service.inject.api.Injection
Annotations:
Inject
Qualifier
Named
NamedByType
Named
, that uses the fully qualified class name of the configured class as nameScope
PerLookup
Singleton
PerRequest
RunLevel
PerInstance
InstanceName
PerInstance
)Describe
Interfaces:
ServicesProvider
InjectionPointProvider
QualifiedProvider
QualifiedInstance
ScopeHandler
Injection into services
A service can have injection points, usually through constructor.
Example:
A dependency (such as
Contract1
above) may have the following forms (Contract
stands for a contract interface, or class):Instance based:
Contract
- injects an instance of the contract with the highest weight from the registryOptional<Contract>
- same as previous, the contract may not have an implementation available in registryList<Contract>
- a list of all available instances in the registrySupplier based (to break cyclic dependency, and to create instances as late as possible):
Supplier<Contract>
Supplier<Optional<Contract>>
Supplier<List<Contract>>
Service instance based (to obtain registry metadata in addition to the instance):
ServiceInstance<Contract>
Optional<ServiceInstance<Contract>>
List<ServiceInstance<Contract>>
Interceptors
Interception provides capability to intercept call to a constructor or a method (even to fields when used as injection points).
Interception is (by default) only enabled for elements annotated with an annotation that is a
Interception.Intercepted
.Annotation processor configuration allows for creating interception "plumbing" for any annotation, or to disable it altogether.
Interception works "around" the invocation, so it can:
Annotation type:
io.helidon.service.inject.api.Interception
Annotations:
Intercepted
Delegate
ExternalDelegate
Delegate
Interfaces:
Interceptor
NamedByType
) will be used as interceptor of methods annotated with that annotation. Interceptor must callproceed
method to handle the interception chain