在匕首2中,是否可以对同一类进行字段注入和构造函数注入? [英] In dagger 2, Is it possible to do field injection and constructor injection for the same class?

查看:87
本文介绍了在匕首2中,是否可以对同一类进行字段注入和构造函数注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以对同一类进行字段注入和构造函数注入?

Is it possible to do field injection and constructor injection for the same class ?

例如:实现就像


  1. 活性

  1. activity


  • 现场注入片段。

片段(活动范围)


  • 非参数构造函数注入(下游)

  • presenter(Fragmentscoped)类的字段注入。


推荐答案

是的,您可以注入同一类中的构造函数,方法和字段。在构建过程中,Dagger将自动注入字段并调用 @Inject 注释的方法。

Yes, you can inject constructors, methods, and fields within the same class. Dagger will automatically inject fields and call @Inject-annotated methods as part of the construction process.

这篇关于在匕首2中,是否可以对同一类进行字段注入和构造函数注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆