Juanpe / Swift-VIPER-Module

Xcode template for VIPER Architecture written in Swift 4
542 stars 113 forks source link

Adds Dependency Injection mechanism and change protocol conformance #28

Open JesusMartinAlonso opened 4 years ago

JesusMartinAlonso commented 4 years ago

This pull request aims to achieve a mechanism to provide dependencies to VIPER modules.

The createModule method of Router class receives a ServiceLocator object as argument. This object provides all the dependencies of the app and will be used to provides dependencies of the module.

In this way, the service locator object is passed between modules.

An example of ServiceLocator implementation can be found here

Apart from these modifications, I have moved the implementation of some protocols to extensions in order to improve legibility (https://github.com/raywenderlich/swift-style-guide#protocol-conformance)

I understand that this pull request tie the user to use the proposed dependency injection mechanism, so I will understand that the PR will be rejected. Anyway, I hope it will be useful for someone.

Thanks!