Swinject: Cannot inherit from non-open class Assembler. Swift 3
Assembler should be marked as open instead of public, otherwise, there is no possibility to subclass it outside.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (10 by maintainers)
Closing the issue, as it has been clarified 😉
I also recommend to take a look at SwiftViper repo (this is not a golden standard, but that is what I use).
Personally I prefer composition over inheritance (and I believe Apple helps you a lot with composition). Also you can refer to
Design Patterns: Elements of Reusable Object-Oriented Softwareand https://en.wikipedia.org/wiki/Composition_over_inheritance for short overview.We also raised similar problem here: https://github.com/Swinject/Swinject/issues/51
As for me, why we can’t build custom class that looks like:
Then we could have an assembler available globally, that stores all other custom assemblers.
Does it make sense?
You probably want to keep Assembler final because it’s job shouldn’t be extendable. As for the VIPER architecture (which I love and use as well!), I create a global Router class that all module router goes through. This class manages the Assembler and can lazy load new AssemblyType instances that bootstrap a VIPER modules into the container via the Assembler. This way you get your module separation plus a nice parent child container relation between your shared managers/services and the VIPER components in each module