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

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

内容简介: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


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

查看所有标签

猜你喜欢:

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

淘宝天猫店是如何运营的

淘宝天猫店是如何运营的

贾真 / 电子工业出版社 / 2017-5 / 49.8

《淘宝天猫店是如何运营的——网店从0到千万实操手册》是由天猫行业Top10卖家、电商圈知名讲师贾真写就的一本运营干货书籍。《淘宝天猫店是如何运营的——网店从0到千万实操手册》的最大卖点就是作者把自己运营店铺的经验系统地总结出来,把碎片化的“干货”形成一个系统的知识体系。句句易懂,读后受益! 现在网上能看到的电商经验,大多是碎片化知识,零散不成体系,其实很难系统地给卖家提供帮助。《淘宝天猫店是......一起来看看 《淘宝天猫店是如何运营的》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

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

在线XML、JSON转换工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具