为什么Dagger使用提供依赖项的工厂的静态实例?在这种情况下,INSTANCE具有静态生存期,并且当依赖项未与任何作用域关联时,甚至都不需要(在这种情况下,使用了proxyProvidesSomeDependency)。即使与范围一起使用,依赖项的工厂为什么也要比依赖项或提供该依赖项的组件长寿?我想念什么吗?
public final class FragmentModule_ProvidesSomeDependencyFactory
implements Factory<SomeDependency> {
private static final FragmentModule_ProvidesSomeDependencyFactory INSTANCE =
new FragmentModule_ProvidesSomeDependencyFactory();
@Override
public SomeDependency get() {
return provideInstance();
}
public static SomeDependency provideInstance() {
return proxyProvidesSomeDependency();
}
public static FragmentModule_ProvidesSomeDependencyFactory create() {
return INSTANCE;
}
public static SomeDependency proxyProvidesSomeDependency() {
return Preconditions.checkNotNull(
FragmentModule.providesSomeDependency(),
"Cannot return null from a non-@Nullable @Provides method");
}
}