/** * Creates an injector for the given set of modules, in a given development stage. * * @throws CreationException if one or more errors occur during injector construction */ public static Injector createInjector(Stage stage, Iterable<? extends Module> modules) { return new InternalInjectorCreator().stage(stage).addModules(modules).build(); } }
public Injector build() { if (shellBuilder == null) { throw new AssertionError("Already built, builders are not reusable."); } // Synchronize while we're building up the bindings and other injector state. This ensures that // the JIT bindings in the parent injector don't change while we're being built synchronized (shellBuilder.lock()) { shells = shellBuilder.build(initializer, bindingData, stopwatch, errors); stopwatch.resetAndLog("Injector construction"); initializeStatically(); } injectDynamically(); if (shellBuilder.getStage() == Stage.TOOL) { // wrap the primaryInjector in a ToolStageInjector // to prevent non-tool-friendy methods from being called. return new ToolStageInjector(primaryInjector()); } else { return primaryInjector(); } }
private boolean isEagerSingleton(InjectorImpl injector, BindingImpl<?> binding, Stage stage) { if (binding.getScoping().isEagerSingleton(stage)) { return true; } // handle a corner case where a child injector links to a binding in a parent injector, and // that binding is singleton. We won't catch this otherwise because we only iterate the child's // bindings. if (binding instanceof LinkedBindingImpl) { Key<?> linkedBinding = ((LinkedBindingImpl<?>) binding).getLinkedKey(); return isEagerSingleton(injector, injector.getBinding(linkedBinding), stage); } return false; }
@Override public Injector createChildInjector(Iterable<? extends Module> modules) { return new InternalInjectorCreator().parentInjector(this).addModules(modules).build(); }
/** * Inject everything that can be injected. This method is intentionally not synchronized. If we * locked while injecting members (ie. running user code), things would deadlock should the user * code build a just-in-time binding from another thread. */ private void injectDynamically() { injectionRequestProcessor.injectMembers(); stopwatch.resetAndLog("Static member injection"); initializer.injectAll(errors); stopwatch.resetAndLog("Instance injection"); errors.throwCreationExceptionIfErrorsExist(); if (shellBuilder.getStage() != Stage.TOOL) { for (InjectorShell shell : shells) { loadEagerSingletons(shell.getInjector(), shellBuilder.getStage(), errors); } stopwatch.resetAndLog("Preloading singletons"); } errors.throwCreationExceptionIfErrorsExist(); }
public Injector createChildInjector(Iterable<? extends Module> modules) { return new InternalInjectorCreator() .parentInjector(this) .addModules(modules) .build(); }
/** * Inject everything that can be injected. This method is intentionally not synchronized. If we * locked while injecting members (ie. running user code), things would deadlock should the user * code build a just-in-time binding from another thread. */ private void injectDynamically() { injectionRequestProcessor.injectMembers(); stopwatch.resetAndLog("Static member injection"); initializer.injectAll(errors); stopwatch.resetAndLog("Instance injection"); errors.throwCreationExceptionIfErrorsExist(); if(shellBuilder.getStage() != Stage.TOOL) { for (InjectorShell shell : shells) { loadEagerSingletons(shell.getInjector(), shellBuilder.getStage(), errors); } stopwatch.resetAndLog("Preloading singletons"); } errors.throwCreationExceptionIfErrorsExist(); }
/** * Creates an injector for the given set of modules, in a given development stage. * * @throws CreationException if one or more errors occur during injector construction */ public static Injector createInjector(Stage stage, Iterable<? extends Module> modules) { return new InternalInjectorCreator().stage(stage).addModules(modules).build(); } }
public Injector createChildInjector(Iterable<? extends Module> modules) { return new InternalInjectorCreator() .parentInjector(this) .addModules(modules) .build(); }
public Injector build() { // Synchronize while we're building up the bindings and other injector state. This ensures that // the JIT bindings in the parent injector don't change while we're being built synchronized (shellBuilder.lock()) { shells = shellBuilder.build(initializer, bindingData, stopwatch, errors); stopwatch.resetAndLog("Injector construction"); initializeStatically(); } injectDynamically(); if (shellBuilder.getStage() == Stage.TOOL) { // wrap the primaryInjector in a ToolStageInjector // to prevent non-tool-friendy methods from being called. return new ToolStageInjector(primaryInjector()); } else { return primaryInjector(); } }
try { for (BindingImpl<?> binding : candidateBindings) { if (isEagerSingleton(injector, binding, stage)) { Dependency<?> dependency = Dependency.get(binding.getKey()); Dependency previous = context.pushDependency(dependency, binding.getSource());
/** * Inject everything that can be injected. This method is intentionally not synchronized. If we * locked while injecting members (ie. running user code), things would deadlock should the user * code build a just-in-time binding from another thread. */ private void injectDynamically() { injectionRequestProcessor.injectMembers(); stopwatch.resetAndLog("Static member injection"); initializer.injectAll(errors); stopwatch.resetAndLog("Instance injection"); errors.throwCreationExceptionIfErrorsExist(); if (shellBuilder.getStage() != Stage.TOOL) { for (InjectorShell shell : shells) { loadEagerSingletons(shell.getInjector(), shellBuilder.getStage(), errors); } stopwatch.resetAndLog("Preloading singletons"); } errors.throwCreationExceptionIfErrorsExist(); }
/** * Creates an injector for the given set of modules, in a given development stage. * * @throws CreationException if one or more errors occur during injector construction */ public static Injector createInjector(Stage stage, Iterable<? extends Module> modules) { return new InternalInjectorCreator().stage(stage).addModules(modules).build(); } }
@Override public Injector createChildInjector(Iterable<? extends Module> modules) { return new InternalInjectorCreator().parentInjector(this).addModules(modules).build(); }
public Injector build() { if (shellBuilder == null) { throw new AssertionError("Already built, builders are not reusable."); } // Synchronize while we're building up the bindings and other injector state. This ensures that // the JIT bindings in the parent injector don't change while we're being built synchronized (shellBuilder.lock()) { shells = shellBuilder.build(initializer, bindingData, stopwatch, errors); stopwatch.resetAndLog("Injector construction"); initializeStatically(); } injectDynamically(); if (shellBuilder.getStage() == Stage.TOOL) { // wrap the primaryInjector in a ToolStageInjector // to prevent non-tool-friendy methods from being called. return new ToolStageInjector(primaryInjector()); } else { return primaryInjector(); } }
injector.jitBindings.values())); for (final BindingImpl<?> binding : candidateBindings) { if (isEagerSingleton(injector, binding, stage)) { try { injector.callInContext(new ContextualCallable<Void>() {
/** * Inject everything that can be injected. This method is intentionally not synchronized. If we * locked while injecting members (ie. running user code), things would deadlock should the user * code build a just-in-time binding from another thread. */ private void injectDynamically() { injectionRequestProcessor.injectMembers(); stopwatch.resetAndLog("Static member injection"); initializer.injectAll(errors); stopwatch.resetAndLog("Instance injection"); errors.throwCreationExceptionIfErrorsExist(); if(shellBuilder.getStage() != Stage.TOOL) { for (InjectorShell shell : shells) { loadEagerSingletons(shell.getInjector(), shellBuilder.getStage(), errors); } stopwatch.resetAndLog("Preloading singletons"); } errors.throwCreationExceptionIfErrorsExist(); }
/** * Creates an injector for the given set of modules, in a given development * stage. * * @throws CreationException if one or more errors occur during injector * construction */ public static Injector createInjector(Stage stage, Iterable<? extends Module> modules) { return new InternalInjectorCreator() .stage(stage) .addModules(modules) .build(); } }
public Injector createChildInjector(Iterable<? extends Module> modules) { return new InternalInjectorCreator() .parentInjector(this) .addModules(modules) .build(); }
public Injector build() { if (shellBuilder == null) { throw new AssertionError("Already built, builders are not reusable."); } // Synchronize while we're building up the bindings and other injector state. This ensures that // the JIT bindings in the parent injector don't change while we're being built synchronized (shellBuilder.lock()) { shells = shellBuilder.build(initializer, bindingData, stopwatch, errors); stopwatch.resetAndLog("Injector construction"); initializeStatically(); } injectDynamically(); if (shellBuilder.getStage() == Stage.TOOL) { // wrap the primaryInjector in a ToolStageInjector // to prevent non-tool-friendy methods from being called. return new ToolStageInjector(primaryInjector()); } else { return primaryInjector(); } }