Skip to content
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

@Context vs @Inject inconsistencies #6698

Closed
barchetta opened this issue Apr 26, 2023 · 1 comment
Closed

@Context vs @Inject inconsistencies #6698

barchetta opened this issue Apr 26, 2023 · 1 comment
Assignees
Labels
3.x Issues for 3.x version branch 4.x Version 4.x jax-rs JAX-RS and Jersey related issues P3 question Further information is requested

Comments

@barchetta
Copy link
Member

barchetta commented Apr 26, 2023

This might just be my ignorance, but we seem to have inconsistencies as to when to use @Inject and when to use @Context. If I am in the weeds here it would be good if somebody could articulate the simple rule our customers should follow to know when to use what.

An example of the problem using Helidon 3.2.0 and the MicroProfile quickstart. In SimpleGreetResource

    @Inject
    private Tracer myTracer;

    @Context
    private ServerRequest serverRequest;

To inject io.opentracing.Tracer I had to use @Inject (could not use @Context).

To inject io.helidon.webserver.ServerRequest I had to use @Context (could not use @Inject).

Is this intentional? Or just what ended up being implemented.

@barchetta barchetta added question Further information is requested jax-rs JAX-RS and Jersey related issues 3.x Issues for 3.x version branch labels Apr 26, 2023
@m0mus m0mus added the P3 label Apr 27, 2023
@barchetta
Copy link
Member Author

Concensus is that we should add a CDI provider for ServerRequest so that you can inject with @Inject

@spericas spericas self-assigned this May 2, 2023
@spericas spericas added the 4.x Version 4.x label May 2, 2023
spericas added a commit to spericas/helidon that referenced this issue May 8, 2023
…I. New functional test to verify both types of injection. See issue helidon-io#6698.
@spericas spericas changed the title 3.x @Context vs @Inject inconsistencies @Context vs @Inject inconsistencies May 8, 2023
spericas added a commit that referenced this issue May 10, 2023
#6784)

* Support for injection of ServerRequest and ServerResponse also via CDI. New functional test to verify both types of injection. See issue #6698.

* Return immutable sets and use existing annotation class.

* Fixed checkstyle.

Signed-off-by: Santiago Pericasgeertsen <[email protected]>

* Simplified registration of beans using fluent API provided by event.

* Use flatMap and throw a CreationException if unable to find instances in context.

* Fixed typo.

Signed-off-by: Santiago Pericasgeertsen <[email protected]>

---------

Signed-off-by: Santiago Pericasgeertsen <[email protected]>
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues for 3.x version branch 4.x Version 4.x jax-rs JAX-RS and Jersey related issues P3 question Further information is requested
Projects
Archived in project
Development

No branches or pull requests

3 participants