android – Dagger 2.2组件构建器模块方法已弃用

栏目: IOS · Android · 发布时间: 6年前

内容简介:http://stackoverflow.com/questions/36521302/dagger-2-2-component-builder-module-method-deprecated

我开始使用匕首2.2,并且不建议使用“组件”构建器中的模块方法.

这是我的应用程序组件:

@Component(modules = ApplicationModule.class)
public interface ApplicationComponent {
    void inject(Application application);
}

和应用模块:

@Module
public class ApplicationModule {
    Application application;

    public ApplicationModule(Application application) {
        this.application = application;
    }

    @Provides
    @Singleton
    Application providesApplication() {
        return application;
    }
}

这是生成的类:

@Generated(
  value = "dagger.internal.codegen.ComponentProcessor",
  comments = "https://google.github.io/dagger"
)
public final class DaggerApplicationComponent implements ApplicationComponent {
  private DaggerApplicationComponent(Builder builder) {
    assert builder != null;
  }

  public static Builder builder() {
    return new Builder();
  }

  public static ApplicationComponent create() {
    return builder().build();
  }

  @Override
  public void inject(Application application) {
    MembersInjectors.<Application>noOp().injectMembers(application);
  }

  public static final class Builder {
    private Builder() {}

    public ApplicationComponent build() {
      return new DaggerApplicationComponent(this);
    }

    /**
     * @deprecated This module is declared, but an instance is not used in the component. This method is a no-op. For more, see https://google.github.io/dagger/unused-modules.
     */
    @Deprecated
    public Builder applicationModule(ApplicationModule applicationModule) {
      Preconditions.checkNotNull(applicationModule);
      return this;
    }
  }
}

如果不使用ComponentBuilder,如何初始化组件?

您应该阅读关于为什么不被弃用的说明.如果您正在使用像IntelliJ或Android Studio这样的IDE,您只需选择该方法并在Windows上点击Control Q即可阅读Javadoc,包括弃用通知.

Javadoc读取:

@deprecated This module is declared, but an instance is not used in the component. This method is a no-op. For more, see 07000.

从这个链接可以看到:

When the Dagger processor generates components, it only requires instances of modules and component dependencies that are explicitly needed to supply requests for a binding.

  • If all of a module’s methods that are used in the component are static, Dagger does not need an instance of that module at all. Dagger can invoke the static methods directly without a module.
  • If a module provides no bindings for a Component, no instance of that module is necessary to construct the graph.

可以肯定地说,您可以忽略弃用.它旨在通知您未使用的方法和模块.一旦您在子图中实际需要/使用应用程序,就需要使用模块,弃用警告将会消失.

http://stackoverflow.com/questions/36521302/dagger-2-2-component-builder-module-method-deprecated


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

关乎天下

关乎天下

关明生 / 学林出版社 / 2005-8 / 8.00元

《关乎天下:中小企业赢取江山的秘诀》收录了作者多年在大企业(如阿里巴巴网站)从事管理基层得到的经验,可为众多中小企业提供招贤纳士和销售管理方面的新思路。一起来看看 《关乎天下》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具