public interface BlogItemWidgetFactory { |
BlogItemWidget create(BlogItem blogItem); |
} |
And BlogItemWidget has an @Assisted parameter for BlogItem in its constructor, right?
// Gin factory modules
install(new GinFactoryModuleBuilder()
.implement(StatisticStrategy.class, Names.named("AveragePriceByCity"), AveragePriceByCityStrategy.class)
.implement(StatisticStrategy.class, Names.named("AveragePriceByBedroom"),AveragePriceByBedroomStrategy.class)
.implement(StatisticStrategy.class, Names.named("AveragePriceByAge"),AveragePriceByAgeStrategy.class)
.build(StatisticStrategyFactory.class));
public interface StatisticStrategyFactory {
@Named("AveragePriceByCity") StatisticStrategy createAveragePriceByCityStrategy(List<House> houses);
@Named("AveragePriceByBedroom") StatisticStrategy createAveragePriceByBedroomStrategy(List<House> houses);
@Named("AveragePriceByAge") StatisticStrategy createAveragePriceByAgeStrategy(List<House> houses);
}
Cheers
When used in tandem with FactoryModuleBuilder, constructors annotated with @AssistedInject indicate that multiple constructors can be injected, each with different parameters. AssistedInject annotations should not be mixed with @Inject annotations. The assisted parameters must exactly match one corresponding factory method within the factory interface, but the parameters do not need to be in the same order. Constructors annotated with AssistedInject are created by Guice and receive all the benefits (such as AOP).