Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
public class AvajeInjectModule implements Extension {

private final BeanScopeBuilder beanScope;
private final BeanScopeBuilder scopeBuilder;

public static AvajeInjectModule of() {
return new AvajeInjectModule(BeanScope.builder());
Expand All @@ -49,8 +49,8 @@ public static AvajeInjectModule of(BeanScopeBuilder beanScope) {
return new AvajeInjectModule(beanScope);
}

public AvajeInjectModule(@NonNull BeanScopeBuilder beanScope) {
this.beanScope = beanScope;
public AvajeInjectModule(@NonNull BeanScopeBuilder scopeBuilder) {
this.scopeBuilder = scopeBuilder;
}

@Override
Expand All @@ -60,7 +60,6 @@ public boolean lateinit() {

@Override
public void install(Jooby application) {

application
.getServices()
.entrySet()
Expand All @@ -69,20 +68,20 @@ public void install(Jooby application) {
var key = e.getKey();
var provider = e.getValue();
if (key.getName() == null) {
beanScope.provideDefault(key.getType(), provider::get);
scopeBuilder.provideDefault(key.getType(), provider::get);
} else {
beanScope.bean(key.getName(), key.getType(), provider);
scopeBuilder.bean(key.getName(), key.getType(), provider);
}
});

final var environment = application.getEnvironment();

beanScope.bean(Environment.class, environment);
beanScope.profiles(environment.getActiveNames().toArray(String[]::new));
scopeBuilder.bean(Environment.class, environment);
scopeBuilder.profiles(environment.getActiveNames().toArray(String[]::new));

// configuration properties
final var config = environment.getConfig();
beanScope.configPlugin(new JoobyPropertyPlugin(config));
scopeBuilder.configPlugin(new JoobyPropertyPlugin(config));

for (var entry : config.entrySet()) {
String name = entry.getKey();
Expand All @@ -91,9 +90,11 @@ public void install(Jooby application) {
if (value instanceof List<?> values) {
value = values.stream().map(Object::toString).collect(Collectors.joining(","));
}
beanScope.bean(name, String.class, value.toString());
scopeBuilder.bean(name, String.class, value.toString());
}

application.registry(new AvajeInjectRegistry(beanScope.build()));
var beanScope = scopeBuilder.build();
application.registry(new AvajeInjectRegistry(beanScope));
application.onStop(beanScope);
}
}
Loading