diff --git a/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/ConfigurationInjectionPoint.java b/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/ConfigurationInjectionPoint.java index d857435d44..7bac615d12 100644 --- a/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/ConfigurationInjectionPoint.java +++ b/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/ConfigurationInjectionPoint.java @@ -40,6 +40,7 @@ * private SomeConfig someConfig; * } * + * \@Settings * public record SomeConfig(@Setting(key = "foo.bar.baz") String fooValue){ } * * @@ -79,11 +80,17 @@ public Result setTargetValue(Object configObject) throws IllegalAccessExce return Result.success(); } + /** + * Not used here, will always return null + */ @Override public ServiceProvider getDefaultServiceProvider() { return null; } + /** + * Not used here + */ @Override public void setDefaultServiceProvider(ServiceProvider defaultServiceProvider) { @@ -92,22 +99,22 @@ public void setDefaultServiceProvider(ServiceProvider defaultServiceProvider) { @Override public Object resolve(ServiceExtensionContext context, DefaultServiceSupplier defaultServiceSupplier) { - // all fields annotated with the @Value annotation - var valueAnnotatedFields = resolveConfigValueFields(context, configurationObject.getType().getDeclaredFields()); + // all fields annotated with the @Setting annotation + var settingsFields = resolveSettingsFields(context, configurationObject.getType().getDeclaredFields()); // records are treated specially, because they only contain final fields, and must be constructed with a non-default CTOR // where every constructor arg MUST be named the same as the field value. We can't rely on this with normal classes if (configurationObject.getType().isRecord()) { // find matching constructor var constructor = Stream.of(configurationObject.getType().getDeclaredConstructors()) - .filter(constructorFilter(valueAnnotatedFields)) + .filter(constructorFilter(settingsFields)) .findFirst() .orElseThrow(() -> new EdcInjectionException("No suitable constructor found on record class '%s'".formatted(configurationObject.getType()))); try { // invoke CTor with the previously resolved config values constructor.setAccessible(true); - return constructor.newInstance(valueAnnotatedFields.stream().map(FieldValue::value).toArray()); + return constructor.newInstance(settingsFields.stream().map(FieldValue::value).toArray()); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new EdcInjectionException(e); } @@ -120,7 +127,7 @@ public Object resolve(ServiceExtensionContext context, DefaultServiceSupplier de var instance = defaultCtor.newInstance(); // set the field values on the newly-constructed object instance - valueAnnotatedFields.forEach(fe -> { + settingsFields.forEach(fe -> { try { var field = pojoClass.getDeclaredField(fe.fieldName()); field.setAccessible(true); @@ -168,7 +175,7 @@ private Predicate> constructorFilter(List args) { } - private @NotNull List resolveConfigValueFields(ServiceExtensionContext context, Field[] fields) { + private @NotNull List resolveSettingsFields(ServiceExtensionContext context, Field[] fields) { return injectionPointsFrom(fields) .map(ip -> { var val = ip.resolve(context, null /*the default supplier arg is not used anyway*/); diff --git a/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/InjectionPoint.java b/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/InjectionPoint.java index 4b0d7d587b..71ce4d6513 100644 --- a/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/InjectionPoint.java +++ b/core/common/boot/src/main/java/org/eclipse/edc/boot/system/injection/InjectionPoint.java @@ -46,7 +46,7 @@ public interface InjectionPoint { * * @param dependencyMap a map containing the current dependency list * @param context the fully constructed {@link ServiceExtensionContext} - * @return success if it can be resolved, a failure otherwise. + * @return successful result containing a (potentially empty) list of injection containers that can provide this service, a failure otherwise. */ Result>> getProviders(Map, List>> dependencyMap, ServiceExtensionContext context);