We've been using Guice for DI in AWS Lambdas, but now are moving to Spring Boot and long running services.
We've got feature toggles working as dynamic proxies in Guice, but need to implement in Spring.
Say we have a SomeFeature
interface and two implementations DisabledImplementation
and EnabledImplementation
.
I can get really close by tagging DisabledImplementation
with @Component("some.feature.disabled")
and EnabledImplementation
with @Component("some.feature.enabled")
and then writing an implementation like this:
@Primary
@Component
public class FlippingFeature implements SomeFeature {
private final SomeFeature enabled;
private final SomeFeature disabled;
private final FeatureFlip featureFlip;
@Inject
public FlippingFeature(@Named("some.feature.enabled") SomeFeature enabled,
@Named("some.feature.disabled") SomeFeature disabled,
FeatureFlip featureFlip) {
this.enabled = enabled;
this.disabled = disabled;
this.featureFlip = featureFlip;
}
@Override
public String foo() {
return featureFlip.isEnabled("some.feature") ? enabled.foo() : disabled.foo();
}
}
But I'd prefer to not write the FlippingFeature
class at all and do it w/ a dynamic proxy hidden away. Can I do this with a custom BeanFactoryPostProcessor
or something else?