Overriding a type for testing is a very useful feature. A possible way to allow for this is supporting qualifiers for types which act at registration time. They could work in a similar fashion as the meta annotation @Qualifier. Options are a meta annotation @Profile or @ProfileQualifier.
A profile qualifier could then be created similar to Spring as follows:
@ProfileQualifier
@Repeatable
@interface Profile {
String value();
}
Possible Implementation
An external strategy should be able to determine if a type is allowed to be registered. The external strategy could be configured with the active profiles, and then given an AnnotatedElement determine if a given type is allowed to be registered or not:
boolean allowRegistration(AnnotatedElement element);
The injector calls this for each type about to be registered and rejects registration if the method returns false. How to reject the registration is still unclear:
- Silently skip registration
- Throw an exception
- Throw an exception only for explicitly registered types (not auto discovered ones)
Externalizing the profile determination allows to create customized implementations of profiles without changes to the core system.
Overriding a type for testing is a very useful feature. A possible way to allow for this is supporting qualifiers for types which act at registration time. They could work in a similar fashion as the meta annotation
@Qualifier. Options are a meta annotation@Profileor@ProfileQualifier.A profile qualifier could then be created similar to Spring as follows:
Possible Implementation
An external strategy should be able to determine if a type is allowed to be registered. The external strategy could be configured with the active profiles, and then given an
AnnotatedElementdetermine if a given type is allowed to be registered or not:The injector calls this for each type about to be registered and rejects registration if the method returns
false. How to reject the registration is still unclear:Externalizing the profile determination allows to create customized implementations of profiles without changes to the core system.