AliSoftware / injectable

A micro framework that leverages Swift Property Wrapper to implement the Service Locator pattern

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Injectable

platforms Carthage compatible

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"

About

A micro framework that leverages Swift Property Wrapper to implement the Service Locator pattern

License:MIT License


Languages

Language:Swift 56.9%Language:Objective-C 43.1%