Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using daggermock with Component.Factory #110

Open
mattinger opened this issue Oct 15, 2021 · 1 comment
Open

Using daggermock with Component.Factory #110

mattinger opened this issue Oct 15, 2021 · 1 comment

Comments

@mattinger
Copy link

Component.Factory is a much simpler way to create a component than the builder pattern. THere's a lot less boilerplate code, plus it mostly forces you into having no arg constructors for your modules, which is a good thing.

However, i'm not seeing a way to provide a way to call the factory class. In addition, our factories generally have a bindsInstance parameter. It would be nice to have a way to customize the entire component creation process, not just via the builder pattern.

@mattinger
Copy link
Author

mattinger commented Oct 15, 2021

As a side note, i also don't think Component.Builder works with dagggermock either if you don't have a builder function for each individual module. From looking at it, the generated builder class creates the no arg versions of the modules automatically. As such, you can't really pass them to dagger mock to work with the overrider, since there is no function to set the module. So while you can have i create a component and customize parts of the builder for the bindsInstance, you can't use the provides functions to override objects in the graph.

@Component.Builder
interface Builder {
    @BindsInstance fun context(context: Context): Builder
    fun build(): MyComponent

Is that a fair assessment?

The reason i ask is that i'm trying to use anvil, so having to enumerate the modules in the builder seems wrong, since they are dynamically collected at compile time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant