Is your feature request related to a problem? Please describe.
Enterprise applications often require enabling or disabling beans according to deployment-specific conditions.
Examples include:
- Activating a tax calculation implementation based on country.
- Enabling integrations only in specific environments.
- Switching between providers based on configuration.
- Enabling feature-flagged functionality.
Today, CDI applications typically solve these scenarios using producer methods, extensions, or custom framework-specific solutions:
@Produces
public TaxCalculator taxCalculator(Config config) {
return "BR".equals(config.country())
? new BrazilTaxCalculator()
: new PortugalTaxCalculator();
}
Although effective, this approach adds boilerplate and separates activation logic from the bean definition.
Describe the solution you'd like
Introduce a standard CDI mechanism to support conditional bean activation.
For example:
@Conditional(CountryCondition.class)
@ApplicationScoped
public class BrazilTaxCalculator implements TaxCalculator {
}
This approach would make bean activation declarative, enhance readability, and reduce reliance on producer-based workarounds.
Describe alternatives you've considered
Currently, similar functionality can be achieved using:
- Producer methods
- Portable Extensions
- Build Compatible Extensions
- Custom framework-specific solutions
Other frameworks offer similar capabilities:
- Apache DeltaSpike:
@Exclude
- Spring:
@Conditional
- Spring:
@Profile
- Spring Boot:
@ConditionalOnProperty
Example:
@Conditional(MyCondition.class)
@Component
class MyService {
}
These examples demonstrate that conditional bean activation is a common requirement across dependency injection frameworks.
Additional context
A standard solution would simplify enterprise use cases such as multi-country deployments, feature flags, environment-specific integrations, and provider selection.
It would also offer a portable alternative to custom extensions and framework-specific annotations, while keeping activation logic close to the bean definition.
Is your feature request related to a problem? Please describe.
Enterprise applications often require enabling or disabling beans according to deployment-specific conditions.
Examples include:
Today, CDI applications typically solve these scenarios using producer methods, extensions, or custom framework-specific solutions:
Although effective, this approach adds boilerplate and separates activation logic from the bean definition.
Describe the solution you'd like
Introduce a standard CDI mechanism to support conditional bean activation.
For example:
This approach would make bean activation declarative, enhance readability, and reduce reliance on producer-based workarounds.
Describe alternatives you've considered
Currently, similar functionality can be achieved using:
Other frameworks offer similar capabilities:
@Exclude@Conditional@Profile@ConditionalOnPropertyExample:
These examples demonstrate that conditional bean activation is a common requirement across dependency injection frameworks.
Additional context
A standard solution would simplify enterprise use cases such as multi-country deployments, feature flags, environment-specific integrations, and provider selection.
It would also offer a portable alternative to custom extensions and framework-specific annotations, while keeping activation logic close to the bean definition.