Using Closures as Dependencies
Vložit
- čas přidán 20. 06. 2024
- In this video we'll explore an alternative way of injecting functionality into your objects. You'll see how you can use closures to inject only the functionality you really need rather than an entire object which makes scoping your dependencies much easier, as well as improving composability and testability of your code.
This video is a companion video for the following blog post: www.donnywals.com/using-closu...
Check out my Swift Concurrency course right here: donnyplus.com/p/practical-swi... - Jak na to + styl
Thanks for the tip! Also these closures make use of withContinuation methods)
Can we have a sample project link ?
Hey! So sorry, I don't have a (publicly available) sample project available for this.
Nice video! Why not make a smaller protocol only giving the needed capability and then make the other protocol conform to the smaller if needed?
You'd end up with loads of small protocols that are composed into larger ones when needed. This can certainly help with scoping and mocking, but at the same time having so many protocols can be quite unwieldy; especially when an object needs to have a composition of parts of protocols and you end up having to break things down even further.
Of course, it might make more sense for some codebases then others. This is just one tool in your toolbelt for injecting and composing dependencies