Allow to enforce Lazy<T>
See original GitHub issueThe 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;
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Lazy Initialization in Spring Boot 2.2 - Baeldung
Here, we use the setLazyInitialization method to configure our application to be initialized lazily. One important note to remember is that ...
Read more >Lazy Initialization - .NET Framework - Microsoft Learn
Explore lazy initialization in .NET, a performance improvement that means an object creation is deferred until the object is first used.
Read more >What is Lazy Loading | Lazy vs. Eager Loading - Imperva
Lazy loading is an optimization technique that delays the loading of objects, allowing for a quicker load time. Find out how it can...
Read more >5 ways to initialize lazy associations and when to use them
5 ways to initialize lazy associations and when to use them ; 1 1. Call a method on the mapped relation ; 2...
Read more >Module Lazy - OCaml library
Module Lazy ; force x forces the suspension x and returns its result. If x has already been forced, Lazy.force x returns the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes. In general, anything that you can inject in a field you can also inject into a constructor.
No, I mean does it support lazy injection in constructor also?