use of ratpack.guice.internal.RatpackBaseRegistryModule in project ratpack by ratpack.
the class Guice method buildInjector.
static Injector buildInjector(Registry baseRegistry, Action<? super BindingsSpec> bindingsAction, Function<? super Module, ? extends Injector> injectorFactory) throws Exception {
List<Action<? super Binder>> binderActions = Lists.newLinkedList();
List<Module> modules = Lists.newLinkedList();
ServerConfig serverConfig = baseRegistry.get(ServerConfig.class);
BindingsSpec bindings = new DefaultBindingsSpec(serverConfig, binderActions, modules);
bindings.module(new RatpackBaseRegistryModule(baseRegistry));
try {
bindingsAction.execute(bindings);
} catch (Exception e) {
throw uncheck(e);
}
modules.add(new AdHocModule(binderActions));
modules.add(new ConfigModule(serverConfig.getRequiredConfig()));
Optional<BindingsImposition> bindingsImposition = Impositions.current().get(BindingsImposition.class);
if (bindingsImposition.isPresent()) {
BindingsImposition imposition = bindingsImposition.get();
List<Action<? super Binder>> imposedBinderActions = Lists.newLinkedList();
List<Module> imposedModules = Lists.newLinkedList();
BindingsSpec imposedBindings = new DefaultBindingsSpec(serverConfig, imposedBinderActions, imposedModules);
imposition.getBindings().execute(imposedBindings);
imposedModules.add(new AdHocModule(imposedBinderActions));
Module imposedModule = imposedModules.stream().reduce((acc, next) -> Modules.override(acc).with(next)).get();
modules.add(imposedModule);
}
Module masterModule = modules.stream().reduce((acc, next) -> Modules.override(acc).with(next)).get();
return injectorFactory.apply(masterModule);
}
Aggregations