Skip to content

Allow to enforce Lazy<T> #218

@konmik

Description

@konmik

The problem:

I can't provide Lazy<T> like this:

    @Provides
    public Lazy<DrawerLayout> provideDrawer

Error:(17, 10) error: android.support.v4.widget.DrawerLayout cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
xx.DocumentListFragment.drawer
[injected field of type: dagger.Lazy<android.support.v4.widget.DrawerLayout> drawer]

Because of that some users of T may try to @Inject T dependency instead of using Lazy. Dagger have no idea that the dependency does not exist at the moment of injection so it may inject null or just crash inside of a module.

Solution: allow to provide Lazy<T> directly.

A temporary workaround I'm using (simplified):

public interface Delayed<T> {
    T get();
}

@Provides
Delayed<DrawerLayout> provideDrawerLayout() {...}

@Inject Delayed<DrawerLayout> drawer;

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions