self.navigationItem.hidesBackButton = true
import com.google.inject.Injector;
import static com.google.inject.Guice.createInjector;
public final class BatchFactory {
private static class Holder {
private static final Injector INJECTOR = createInjector(new BatchModule());
private static final batchProvider PROVIDER_INSTANCE = INJECTOR
.getInstance(BatchProvider.class);
}
public static BatchProvider getProviderInstance() {
return Holder.PROVIDER_INSTANCE;
}
}
public class BatchModule extends AbstractModule {
@Override
protected void configure() {
bind(BatchProvider.class).to(
BatchProviderImpl.class);
}
}
是接口,BatchProvider
是类实现。
这里我使用类BatchFactory来创建BatchProviderImpl
类的@Singleton
实例。
我可以使用google guice的@Singleton注释来BatchProviderImpl
类BatchFactory
答案 0 :(得分:1)
请参阅duplicate question,您可以
bind(Service.class).to(ServiceImpl.class).in(Singleton.class);
或者:
@Provides @Singleton
public ServiceImpl providesService() {
return new ServiceImpl();
}