Guice40

Sam Berlin edited this page May 20, 2015 · 15 revisions

Guice 4.0

Released April 28, 2015

Maven

Guice:

<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>4.0</version>
</dependency>

Guice (No AOP):

<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>4.0</version>
  <classifier>no_aop</classifier>
</dependency>

Extensions:

<dependency>
  <groupId>com.google.inject.extensions</groupId>
  <artifactId>guice-${extension}</artifactId>
  <version>4.0</version>
</dependency>

Downloads

Docs

Changes since Guice 3.0

Some highlights:
Details, per core + extension...
Guice Core:
  • Changed validation on @Provides methods -- it is now forbidden to override them.
  • Changed validation on null being passed into @Provides method parameters. Parameters must now be @Nullable to allow null (the same as injecting methods or constructors).
  • Changed the way Singletons are initialized -- there is no system-wide lock anymore. Singletons can now be instantiated concurrently.
  • Changed requireExplicitBindings on child injectors or PrivateModules so that implicit bindings aren't promoted to the parent injector/module, even if the parent doesn't have requireExplicitBindings set.
  • Added ProvisionListener (installed with Binder.bindListener) to intercept provisioning.
  • Added Binder.requireAtInjectOnConstructors to prevent Guice from creating instances of classes that have no-args public constructors w/o @Inject.
  • Added Binder.requireExactBindingAnnotations to prevent Guice from allowing a binding for @Named Foo to fulfill a request for @Named("foo") Foo, if the latter was missing but the former existed. (This applies to all parameterized annotations, not just @Named.)
  • Added ElementSource, returned from Binding.getSource when possible, to get more detailed information about the binding. This includes keeping track of all the modules in the path that led to the binding.
  • Added an SPI for @Provides methods. Call Binding.acceptTargetVisitor with the new ProvidesMethodTargetVisitor.
  • Added ModuleAnnotatedMethodScanner (installed by Binder.scanModulesForAnnotatedMethods) to allow extensions to hook into Modules, scanning for methods annotated with @Provides-like methods and creating bindings.
  • Added the ability to to stop recording line numbers of bindings, which can increase startup time drastically (at the expense of less useful error messages). (Use the system property guice_include_stack_traces set to OFF, ONLY_FOR_DECLARING_SOURCE (the default), or COMPLETE).
  • Added LinkedBindingBuilder.toProvider(javax.inject.Provider), for better JSR330 compatibility.
  • Added InjectionPoint.forMethod & Binder.getProvider(Dependency) to allow building injection points off arbitrary methods.
  • Allowed duplicate listener, interceptor & scope bindings to be ignored (instead of failing or installing them twice).
  • Allowed method interceptors to capture the intercepted method and invoke it later.
  • Allowed @ProvidedBy to work with enums (issue 295).
  • Improved error messages to list out all modules that led to a failed binding.
  • Improved error messages when requestStaticInjection is called on an interface.
  • Fixed the way Key works with annotations, so that it considers @Annotation is equal to Annotation.class if the annotation has all optional methods.
  • Fixed interceptors to allow intercepting bridge methods that javac automatically creates sometimes.
  • Fixed circular dependencies between providers (issue 626).
  • Fixed classloader leak relating to AOP (issue 643).
  • Fixed anonymous TypeLiteral/Key instances so they don't retain references to the enclosing Module (issue 910).
  • Fixed exceptions when encountering circular just-in-time bindings, when scopes cached proxies for circular dependencies, and when requestInjection (and others) try to inject the same object more than once in a different order than they were bound.
  • Fixed currentStage() when used in Modules.override.
  • Fixed internal calls to System.getProperty so exceptions are ignored.
  • Optimized memory required when dealing with child injectors (issue 756).
  • Optimized @Provides methods (by invoking them through cglib, saving ~200-300ns per method invocation).
  • Optimized memory required for keeping binding source information.
  • Optimized TypeConverters.
Servlet extension
  • Added ServletScopes.transferRequest to allow the current scope to be transferred to a different callable.
  • Added ServletScopes.isRequestScoped to see if a binding is request scoped.
  • Added the Key being requested into OutOfScopeException's message.
  • Added a @ScopingOnly GuiceFilter that can be injected to provide scoping functionality without the dispatching.
  • Fixed ordering of filter processing -- the first binding is processed first. (It could have been in an arbitrary order if filters were set by different modules.)
  • Fixed the request/response passed to filters & servlets so they get the latest request/response (even if it's wrapped by an earlier filter).
  • Fixed manipulation of the servlet path info (issue 372).
  • Fixed manipulation of the context path.
  • Fixed pattern matching to ignore the query portion of the URI (issue 379).
  • Fixed to decode the PathInfo (issue 745).
  • Fixed exception when getCookies returned null.
  • Fixed to work with requireExplicitBindings.
  • Optimized the stack size when calling filters and trimmed excessive calls to doFilter from exception stack traces.
  • Optimized performance per served request.
  • Optimized scopeRequest.
Multibinder
  • Changed Multibinder to also bind a Collection<Provider<T>> and Collection<javax.inject.Provider<T>>.
  • Changed MapBinder to also bind a Map<K, javax.inject.Provider<V>>.
  • Added OptionalBinder, to allow frameworks to depend on something that users may or may not bind. (Also allows a default value for a binding that users can change.)
  • Added MultibindingsScanner to allow using @ProvidesIntoSet, @ProvidesIntoMap and @ProvidesIntoOptional on methods in modules.
  • Fixed Multibinder/MapBinder to work better with Modules.override, ignoring exact same bindings instead of binding them twice. (Most usages of permitDuplicates should be unnecessary now.)
  • Fixed Multibinder & MapBinder so they can't conflict with each other (issue 670).
  • Improved error messages for duplicate bindings so it tells you what the duplicates were and where they were bound.
AssistedInject
  • Changed the validation on assisted injected classes to fail if the class has a scoping annotation.
ThrowingProvider
Grapher
  • Allowed injecting non-scoped graphers.
  • Fixed the way PrivateModules are handled to show exposed nodes (issue 489).
  • Fix corrupt/bad looking graphs (issue 663).
  • Fix incorrect grapher config (issue 755).
Persist
  • Fixed so that log4j.properties file is not in the jar.
  • Fixed to remove the entityManager even if close() throw an exception (issue 597).
  • Allowed JPA properties to be arbitrary Objects (in addition to Strings).

Migrating from Guice 3.0

See the JDiff change report for complete details.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.