Injectable
Context
Injectable is a Swift micro framework that leverages Property Wrapper to implement the Service Locator pattern, through a custom attribute @Injectable
.
Here's an example of how it can be used:
protocol Servicing {
func action()
}
class Service: Servicing {
func action() {
print("I'm performing a service π")
}
}
Resolver.register(Servicing.self, { return Service() })
class MyController {
@Injectable var service: Servicing
func work() {
self.service.action()
}
}
let controller = MyController()
controller.work() // I'm performing a service π
Requirements
Xcode 11+ & Swift 5.1
Installation
Carthage
Add the following to your Cartfile
:
github "vincent-pradeilles/injectable"