Skip to content

Commit

Permalink
allow @nAmed Property Injection
Browse files Browse the repository at this point in the history
  • Loading branch information
SentryMan committed Apr 25, 2024
1 parent d9e6a98 commit 7177111
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
package io.jooby.avaje.inject;

import java.util.List;
import java.util.stream.Collectors;

import com.typesafe.config.Config;

import io.avaje.inject.BeanScope;
Expand Down Expand Up @@ -65,10 +68,24 @@ public void install(Jooby application) throws Exception {
beanScope.bean(key.getName(), key.getType(), e.getValue());
}
});

final var environment = application.getEnvironment();
beanScope.profiles(environment.getActiveNames().toArray(String[]::new));
beanScope.propertyPlugin(new JoobyPropertyPlugin(environment.getConfig()));
beanScope.bean(Config.class, environment.getConfig());

// configuration properties
final var config = environment.getConfig();
beanScope.propertyPlugin(new JoobyPropertyPlugin(config));
beanScope.bean(Config.class, config);

for (var entry : config.entrySet()) {
String name = entry.getKey();
Object value = entry.getValue().unwrapped();

if (value instanceof List<?> values) {
value = values.stream().map(Object::toString).collect(Collectors.joining(","));
}
beanScope.bean(name, String.class, value.toString());
}

application.registry(new AvajeInjectRegistry(beanScope.build()));
}
Expand Down

0 comments on commit 7177111

Please sign in to comment.