Middle+
List two ways to transfer objects when creating an instance of the Dagger library.
sobes.tech AI
Answer from AI
-
Using a module annotated with
@Module. Inside the module, methods annotated with@Providessupply dependency instances.@Module class MyModule { @Provides fun provideMyObject(): MyObject { return MyObject() } } -
Using a constructor annotated with
@Inject. Dagger can create an instance of such a class if all its constructor dependencies are also provided.class MyObject @Inject constructor() { // ... }