google / google/guice

Support for Lazy<T> like Dagger

Open
#852 13 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

I've implemented a version of [Dagger's `Lazy`](https://github.com/square/dagger/blob/master/core/src/main/java/dagger/Lazy.java) in [Sangria](https://github.com/tavianator/sangria/blob/master/sangria-lazy/src/main/java/com/tavianator/sangria/lazy/Lazy.java). But it's somewhat limited; `Lazy` works automatically but `@Annotated Lazy` requires you to explicitly add a binding. That's about as good as an extension can do. There are some alternatives:
1. Have Guice support its own `Lazy` out of the box, in a similar way to how `Provider` injection works now.
2. Have Guice expose some kind of support for "pluggable bindings." Then I could write something like `bind(new LazyKeyMatcher()).to(new LazyGuicePlugin())` and the plugin would generate bindings on the fly.

Is there any interest in doing something like 2? If so I can code up a proof of concept.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.