google / google/fruit

RFE: Real providers (classes)

Open
#129 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.9k
Forks
202
PR merge metrics
No merged PRs in 30d

Description

Adopted Fruit for a recent project, have been a big Guice user in the past. There was a learning curve but I'm overall very happy with it. Big thanks.

The one thing that I desperately miss (from Guice) is providers. I don't want a lambda to re-implement every place (i.e. unit test) I depend on the thing, I don't want to define a whole bunch of global level Component functions. (I tried building everything from Components like the docs suggest at first, it just does not work for me, it gets in the way.)

I just want to be able to `.bind()`, where `ThingProvider` defines an (e.g.) `public: T Get()` (implements `FruitProviderInterface`?), and then be able to depend on a concrete `T` anywhere I need it. All the complexity of building that thing is in one place, and I can test it. And I can define a simpler `ThingProviderFake` for tests of everything that (transitively) depends upon it instead, and bind it with just one line.

To date I've been implementing my providers, and everywhere I depend upon them I manually `Get()` the `T` out, turning the provider into the instance. (Except in the one case where I store the provider, because other things need to happen before I can `Get()` from it.) Would be nice to eliminate that boilerplate.

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.