-
-
Notifications
You must be signed in to change notification settings - Fork 115
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 Factory between different targets in a package and app #213
Comments
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.
The text was updated successfully, but these errors were encountered: