Open LucasVanDongen opened 3 months ago
Covered quite a bit of this in the documentation. https://hmlongco.github.io/Factory/documentation/factory/modules
Especially the section on Separating Dependencies.
Thanks for the link!
I have been thinking a lot lately about this, I tried a bunch of things myself as well, but there seems to be no compile-safe way to guarantee that both sides of the fence implement a dependency, unless we start doing everything manually again.
That's why the recommendation for multi-module development is to make them optionals.
Or code the base dependency definition with a stub or nop.
Use Case
I'm working on improving my build times and previews speed and reliability by turning all of my major features into Packages. The strategy is to hide every dependency behind a protocol, and then only export 3rd party dependencies when I'm returning the actual implementation, but not when I'm running Previews.
This is the structure:
This works great and I'm back to snappy Previews because the only thing I build is View / ViewModel code, some lightweight MockSpies (generated by Sourcery).
However I have no idea how to fit Factory into this. The ViewModels and Views expect registrations in Containers but I cannot give those yet because they're different between the App that is consuming my UI target and my Previews that inject the mocks instead.
So the UI relies on the App itself to register these dependencies (coming from the Implementations target) but the Previews module has its own registrations. The UI module doesn't understand this and fails to build.
Solution Direction
I'm looking for a way where I can "promise" the UI module that the dependencies will be set at run-time, in a compile-time safe way, by the target or app that consumes it. I tried messing around with protocols but couldn't get anything to work. The only thing I saw possible so far is injecting the dependencies Container manually.