Swift Programming
Published in

Swift Programming

Dependency Injection with the Cake Pattern


Lets get to the CODE

We will start by creating a struct which will be our model. This will hold our data that we will be receiving.

This is where the magic happens

Lets create another protocol and name it ProductsRepositoryInjectable. On this protocol, lets add a property of type ProductsRepository and make this a read only property. We will now create a protocol extension, that will provide us with a default implementation for this property. This being the ProductRepositoryImplementation we created earlier.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Peter-John Welcome

Freelance Senior Mobile Engineer, Google Developer Expert for Firebase, Photographer