Dirk icon indicating copy to clipboard operation
Dirk copied to clipboard

Support for Profiles

Open hjohn opened this issue 3 years ago • 0 comments

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:

  1. Silently skip registration
  2. Throw an exception
  3. 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.

hjohn avatar May 12 '22 09:05 hjohn