Generated by
JDiff

com.google.inject.assistedinject Documentation Differences

This file contains all the changes in documentation in the package com.google.inject.assistedinject as colored differences. Deletions are shown like this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.

Class AssistedInject

Constructors When used in tandem with FactoryModuleBuilder, constructors annotated with {@code @AssistedInject} indicate that theymultiple constructors can be instantiatedinjected, by theeach with different parameters. AssistedInject annotations should not be mixed with {@literal @}FactoryProviderInject annotations. Each constructorThe assisted parameters must exactly match one corresponding factory method withinmethod within the factory interface. , but Constructorthe parameters must be either supplied bydo not need to be in the factorysame interfaceorder. and marked with Constructors annotated with @Assisted,AssistedInject orare they must becreated by Guice injectableand receive all the benefits (such as AOP). @deprecated

Obsolete Usage: When used in tandem with FactoryProvider now, works betterconstructors annotated with the standard {@literalcode @InjectAssistedInject} trigger a "backwards compatibility annotationmode". When using thatThe assisted parameters annotation,must parametersexactly arematch one matched by namecorresponding factory method andwithin the factory interface type rather than and all must be in the same byorder positionas listed in the factory. In additionthis backwards compatable mode, valuesconstructors thatannotated with AssistedInject are not created useby Guice and thus receive none of the standardbenefits. {@literal @Inject}

Constructor constructor parameters must be either supplied annotation are eligible forby the factory interface methodand marked with @Assisted, or they must interceptionbe injectable. @author jmourits@google.com (Jerome Mourits) @author jessewilson@google.com (Jesse Wilson)


Class FactoryProvider

Obsolete. Prefer FactoryModuleBuilder for its more concise API and additional capability.

Provides a factory that combines the caller's arguments with injector-supplied values to construct objects.

Defining a factory

Create an interface whose methods return the constructed type, or any of its supertypes. The method's parameters are the arguments required to build the constructed type.
public interface PaymentFactory {
   Payment create(Date startDate, Money amount);
 }
You can name your factory methods whatever you like, such as create, createPayment or newPayment.

Creating a type that accepts factory parameters

{@code constructedType} is a concrete class with an {@literal @}Inject-annotated constructor. In addition to injector-supplied parameters, the constructor should have parameters that match each of the factory method's parameters. Each factory-supplied parameter requires an {@literal @}Assisted annotation. This serves to document that the parameter is not bound by your application's modules.
public class RealPayment implements Payment {
   {@literal @}Inject
   public RealPayment(
      CreditService creditService,
      AuthService authService,
      {@literal @}Assisted Date startDate,
      {@literal @}Assisted Money amount) {
     ...
   }
 }
Any parameter that permits a null value should also be annotated {@code @Nullable}.

Configuring factories

In your module, bind the factory interface to the returned factory:
bind(PaymentFactory.class).toProvider(
     FactoryProvider.newFactory(PaymentFactory.class, RealPayment.class));
As a side-effect of this binding, Guice will inject the factory to initialize it for use. The factory cannot be used until the injector has been initialized.

Using the factory

Inject your factory into your application classes. When you use the factory, your arguments will be combined with values from the injector to construct an instance.
public class PaymentAction {
   {@literal @}Inject private PaymentFactory paymentFactory;

   public void doPayment(Money amount) {
     Payment payment = paymentFactory.create(new Date(), amount);
     payment.apply();
   }
 }

Making parameter types distinct

The types of the factory method's parameters must be distinct. To use multiple parameters of the same type, use a named {@literal @}Assisted annotation to disambiguate the parameters. The names must be applied to the factory method's parameters:
public interface PaymentFactory {
   Payment create(
       {@literal @}Assisted("startDate") Date startDate,
       {@literal @}Assisted("dueDate") Date dueDate,
       Money amount);
 } 
...and to the concrete type's constructor parameters:
public class RealPayment implements Payment {
   {@literal @}Inject
   public RealPayment(
      CreditService creditService,
      AuthService authService,
      {@literal @}Assisted("startDate") Date startDate,
      {@literal @}Assisted("dueDate") Date dueDate,
      {@literal @}Assisted Money amount) {
     ...
   }
 }

Values are created by Guice

Returned factories use child injectors to create values. The values are eligible for method interception. In addition, {@literal @}{@literal Inject} members will be injected before they are returned.

Backwards compatibility using {@literal @}AssistedInject

Instead of the {@literal @}Inject annotation, you may annotate the constructed classes with {@literal @}AssistedInject. This triggers a limited backwards-compatability mode.

Instead of matching factory method arguments to constructor parameters using their names, the parameters are matched by their order. The first factory method argument is used for the first {@literal @}Assisted constructor parameter, etc.. Annotation names have no effect.

Returned values are not created by Guice. These types are not eligible for method interception. They do receive post-construction member injection. @param The factory interface @author jmourits@google.com (Jerome Mourits) @author jessewilson@google.com (Jesse Wilson) @author dtm@google.com (Daniel Martin) @deprecated use FactoryModuleBuilder instead.