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


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

查看所有标签

猜你喜欢:

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

JavaScript and Ajax for the Web, Sixth Edition

JavaScript and Ajax for the Web, Sixth Edition

Tom Negrino、Dori Smith / Peachpit Press / August 28, 2006 / $24.99

Book Description Need to learn JavaScript fast? This best-selling reference’s visual format and step-by-step, task-based instructions will have you up and running with JavaScript in no time. In thi......一起来看看 《JavaScript and Ajax for the Web, Sixth Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具