Possible pit solutions using dagger2 in kotlin

What is dagger2?

Dagger2 is an open source library based on Java annotations that completes dependency injection in the compilation stage. It is mainly used for decoupling between modules to facilitate testing.

1、 Kotlin dagger2 configuration

build.gradle

AppComponent

AppModule

Application

After the above configuration is completed, you can happily use dagger2 in kotlin.

For more information about kotlin dagger2 configuration, please refer to here: https://www.oudahe.com/p/40232/

2、 Pit encountered by kotlin using dagger2

At that time, I wanted to inject the presenter into the activity. The code is as follows. I couldn't figure it out without making projiect

Pit 1

Then I converted the kotlin code into bytecode and then into Java code, and found that the presenter was private

As we all know, injected objects cannot be private

You can compile successfully

Pit 2

summary

The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>