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

Enable CDI beans based on profiles #6238

Closed
jonathanvila opened this issue Dec 17, 2019 · 17 comments
Closed

Enable CDI beans based on profiles #6238

jonathanvila opened this issue Dec 17, 2019 · 17 comments
Labels
area/arc Issue related to ARC (dependency injection) kind/enhancement New feature or request
Milestone

Comments

@jonathanvila
Copy link

Description
Based on a profile especified (env var) an Annotated bean will be added to the context or filtered out.

@jonathanvila jonathanvila added the kind/enhancement New feature or request label Dec 17, 2019
@geoand
Copy link
Contributor

geoand commented Dec 17, 2019

cc @mkouba

@geoand geoand added the area/arc Issue related to ARC (dependency injection) label Dec 17, 2019
@geoand
Copy link
Contributor

geoand commented Dec 17, 2019

So the idea is to conditionally create a bean based on whether or not a profile is active, correct?

Of course this can't work with profiles defined at runtime, but seems very useful for build time profiles

@jonathanvila
Copy link
Author

Exactly that is the idea.
Basically we can activate few beans on "test" profile, others on "prod" profile..... specially databases related beans, file persistance beans.....

@mkouba
Copy link
Contributor

mkouba commented Dec 18, 2019

Of course this can't work with profiles defined at runtime, but seems very useful for build time profiles

Hm, that's something I'm concerned about. The first question will be "I do set my profile to staging when running my app and the beans are still there, why?".

@geoand
Copy link
Contributor

geoand commented Dec 18, 2019

Yes...

Just an idea: Perhaps we could expand the concept of profile to encompass the build-time vs run-time difference? Or would that make things more confusing... I don't know :)

@jonathanvila
Copy link
Author

jonathanvila commented Dec 18, 2019 via email

@geoand
Copy link
Contributor

geoand commented Dec 18, 2019

The issue is that -Dquarkus.profile=whatever does have an effect on user supplied properties (properties in application.properties prefixed with %whatever like %whatever.greeting.message) will be active.

So if we introduce the profiles support for beans users will get the false sense that if they use -Dquarkus.profile=whatever then beans for the whatever profile will be activated. So we would need to find a good user experience that would allow the functionality you propose but that wouldn't confuse users.

@jonathanvila
Copy link
Author

jonathanvila commented Dec 18, 2019 via email

@geoand
Copy link
Contributor

geoand commented Dec 18, 2019

Exactly. So if we are to make something like this available for CDI beans, we need to be very careful how to make a good user experience

@mkouba
Copy link
Contributor

mkouba commented Dec 18, 2019

So then que quarkus profile is a Runtime feature not a build feature?

IIUIC it's both - the build-time and the runtime feature.

@geoand
Copy link
Contributor

geoand commented Dec 18, 2019

So then que quarkus profile is a Runtime feature not a build feature?

IIUIC it's both - the build-time and the runtime feature.

My interpretation is that run-time implies build-time as well :)

@jonathanvila
Copy link
Author

jonathanvila commented Dec 18, 2019 via email

@geoand
Copy link
Contributor

geoand commented Dec 18, 2019

Besides affecting the configuration stuff, it also set implicitly when running tests and the dev mode

@stuartwdouglas
Copy link
Member

I don't think that the build time only aspect of this is an issue, as we already have the concept of build time only config.

@geoand
Copy link
Contributor

geoand commented Mar 18, 2020

I also like this idea a lot, but I my concern is summed up very well by this comment from @mkouba

@stuartwdouglas
Copy link
Member

It is now possible to enable CdI beans via config, and #9933 allows them to be enabled per test easily.

@mkouba
Copy link
Contributor

mkouba commented Jun 16, 2020

For the record - there's also @IfBuildProfile and @UnlessBuildProfile: https://quarkus.io/guides/cdi-reference#enabling-beans-for-quarkus-build-profile

@gsmet gsmet added this to the 1.6.0 - master milestone Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants