DaggerMock
DaggerMock copied to clipboard
Using daggermock with Component.Factory
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.
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.