Sobes.tech
Junior — Middle

What annotation in Dagger is used to inject an external dependency into a component?

sobes.tech AI

Answer from AI

To inject an external dependency into a Dagger component, the @Component.Builder or @Component.Factory annotation is used, and to pass the dependency itself — the @BindsInstance annotation.

For example, if you need to pass an object created outside of Dagger, you can use @BindsInstance in the component's builder:

@Component
interface MyComponent {
    void inject(MyClass target);

    @Component.Builder
    interface Builder {
        @BindsInstance
        Builder externalDependency(ExternalDependency dep);
        MyComponent build();
    }
}

Thus, @BindsInstance allows injecting an external dependency into the component's dependency graph.