current position:Home>What are the differences among the three Android annotation frameworks dagger, hilt and Koin?, Retrofit benefits
What are the differences among the three Android annotation frameworks dagger, hilt and Koin?, Retrofit benefits
2022-02-04 16:47:56 【mb61ab4e6f736e7】
[]( )Dagger
==================================================================
If we want to Dagger Provide an instance of a class , All we have to do is add... To the constructor [email protected]? annotation .
After adding this annotation ,Dagger? A... Will be generated for this class at build time ?Factory. Under this use case , Because its class name is ?CompositeAdapter, It generates a file called ?CompositeAdapter**_**Factory Class .
This class contains the creation of ?CompositeAdapter? Class .
As you can see, the factory class implements ?get()? And returned a new ?CompositeAdapter? example . This is actually an implementation of this kind ?Provider ? Interface . Other classes can use ?Provider? Interface to get an instance of a class .
[]( ) If we use Hilt Instead of Dagger Well ?
===================================================================================
In this case , It doesn't make any difference .Hilt? Is an internal use ?Dagger? The library of , The class I show you is composed of ?Dagger? Generated . If you use ?Hilt, It does generate some additional classes for us , These classes simplify ?Dagger? Use , And reduce the amount of boilerplate code we need to write . But the core remains the same .
[]( )Koin
================================================================
Koin? And ?Dagger? as well as ?Hilt? comparison , The approach to managing dependencies is completely different . To be in Koin Register dependencies in , We won't use any annotations , because Koin No code will be generated . contrary , We must provide factories for modules , These modules will be used to create instances of each class required in the project .
Koin? Add references to these factory classes to ?InstancesRegistry? Class , This class contains references to all the factories we write .
The ?map? Medium ?key? Is the full name of the class or the name provided when using named parameters . The corresponding value is the factory we write , Will be used to create an instance of the class .
To get dependencies , We need to call ?get()?( For example, in a factory class ) Or through ?activities? or ?fragments? Call in ?inject()? Delegate properties , So as to load ?get().get() Method will find the factory registered for the class of the given type , And inject it into it .
[]( ) What's the impact? ?
==================================================================
Dagger Generate code to provide dependencies , and Koin No code generation , This actually has some impact .
1. Error handling
because Dagger? Is a compile time dependency injection framework , If we forget to provide some dependencies , We will know our mistakes almost immediately , Because our project will fail to build .
for example , If we forget to write to the constructor ?CompositeAdapter? Add [email protected]? annotation , And try to inject it into fragment in , The build will fail , And display the appropriate error , Tell us exactly what's wrong .
stay Koin The situation is different in , Because it doesn't generate any code . If we forget to be ?CompositeAdapter Class add factory , The application will be successfully built , But it will throw out ?RuntimeException? Once we request an instance of this class . It may happen when the application starts , So we may notice it immediately , But it may also happen later on other screens or when the user performs certain actions .
2. Impact on build time
Koin The advantage of not generating any code is : It has a much smaller impact on our build time .Dagger? You need to use an annotation processor to scan the code and generate the appropriate classes . This may take some time , It may slow down our construction .
summary
Finally, in order to help you understand Android The principle of relevant knowledge points and interview related knowledge , Here's what I've collected 24 set tencent 、 Bytes to beat 、 Ali 、 Baidu 2019-2021 Analysis of the real interview questions , I organized the technical points into Video and PDF( In fact, it took a lot more energy than expected ), package The context of knowledge + A lot of details .
also ? Advanced architecture technology advanced brain map 、Android Develop interview materials ? To help you learn and upgrade , It also saves time for people to search information on the Internet to learn , You can also share it with your friends and learn together .
Online learning Android A lot of information , But if the knowledge learned is not systematic , When you encounter a problem, you just have a taste of it , No further study , So it's hard to really improve the technology . I hope this systematic technical system has a direction reference for you .
2021 In spite of the bumpy road , It's all about Android To fall , however , Don't panic , Make your own plan , Learn from yourself , Competition is everywhere , This is true of every industry . Believe in yourself , Nothing is impossible , Only the unexpected . Wish you all 2021 Everything is going well in the new year .
This article has been CODING Open source project :《Android Summary of learning notes + Mobile architecture video + The real interview question of Dachang + Project source code 》 Included
copyright notice
author[mb61ab4e6f736e7],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041647552093.html
The sidebar is recommended
- How does uniapp enable wechat applet users to automatically register and log in without authorization
- Java springboot queries the database. The result in the database is empty. Will it return null or throw an exception directly at this time
- Vue import excel table, interface error
- Why is no target connected always displayed
- The sum of the first n series can be solved by a lucky person
- How to calculate the time complexity
- Why does Java report an error?
- Regular expressions that allow numbers, English, and some special characters
- Please answer the questions about # C #!
- Is there a method to realize or call sending SMS
guess what you like
-
The most hardcore Java programmers in the whole network must have basic knowledge (I)
-
How to use selenium to solve the problem of continuing reading in a library
-
In simple terms, MySQL index optimization topic sharing | interview cycle
-
How to convert the specific template type of template function into string in C + +
-
Why is the result 3 4
-
DDD (Domain Driven Design) thought interpretation and excellent practice GGG
-
MFC project operation error is not a class or namespace
-
Builder pattern of Java design pattern
-
How to change the inconsistency of two Y-axis axes of echarts? The values of the left and right Y axes are uncertain
-
C language to find the volume and surface area of the ball, the volume is equal to the surface area?
Random recommended
- Analysis of shallow cloning and deep cloning in Java
- main. JS introduces Ant Design Vue
- Can some Java dictionaries store null?
- I need HTML when downloading the boost library with WGet on CentOS tar
- [test development] knowledge points - spring cache + redis is used to cache data in the project
- VO entity deposit value is empty? VO entity content data is empty
- Logic of process scheduling in Linux kernel source code analysis
- How to open a file with relative path in C + + under QT environment
- 30000 words to talk about redis (VI)
- It's great to use debug a!
- Netcom infinite integral code
- How to find element label in MATLAB
- 2021 is gone, and 2022 is my year-end summary of 2021
- How to use wechat applet for this page
- Why is the second% s not output
- Badboy recording script website can't be opened in ie. why can't badboy record after changing the default browser?
- fatal error LNK1113: invalid machine type
- Crazy God said that there was a 404 problem in the ssmbuild project in Java
- What is the spark job submission process?
- How about the performance comparison of query acceleration in maxcompute?
- What is a database connection pool?
- What is the workflow of spark streaming and how is it different from storm?
- What is the application scenario of streaming data writing in maxcompute?
- What are the source databases supported by DTS self built Mysql to synchronize to RDS MySQL?
- What is the process of establishing a connection between an application and a database?
- What are the target databases supported by DTS self built Mysql to synchronize to RDS MySQL?
- What are the differences and connections between the ML and mllib packages of spark?
- What are the benefits of database connection pooling?
- What are the application scenarios of query acceleration in maxcompute?
- What are the prerequisites for DTS self built Mysql to synchronize to RDS MySQL?
- How does MySQL query statements?
- What are the similarities and differences between yarn cluster and yarn client?
- What are the restrictions on the source database of DTS self built MySQL synchronized to RDS MySQL?
- What is the difference between map and mappartitions?
- What database server performance analysis methods and commands does MySQL have?
- What are the other limitations of DTS self built MySQL synchronization to RDS MySQL?
- What is the difference between MySQL blob and text?
- What is the description of the special case of DTS self built MySQL synchronizing to RDS MySQL?
- What types of locks are there in MySQL?
- DTS self built MySQL synchronizes to RDS. What synchronization architectures does MySQL support?