Popularity
2.5
Growing
Activity
0.0
Stable
113
3
5

Programming language: Swift
License: MIT License
Latest version: v0.4

Locatable alternatives and similar libraries

Based on the "Dependency Injection" category.
Alternatively, view Locatable alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of Locatable or a related project?

Add another 'Dependency Injection' Library

README

Locatable

platforms pod Carthage compatible

Context

Locatable is a Swift micro framework that leverages Property Wrappers to implement the Service Locator pattern, through a custom attribute @Locatable.

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 ๐Ÿ˜Š")
    }
}

Locator.register(Servicing.self, { return Service() })

class MyController {
    @Locatable(.sharedInstance) var service: Servicing

    func work() {
        self.service.action()
    }
}

let controller = MyController()

controller.work() // I'm performing a service ๐Ÿ˜Š

For convenience, some shorthand syntax are also available:

// leverages @autoclosure
Locator.register(Servicing.self, Service())

// leverages default argument values
Locator.register { return Service() as Servicing }

Service locating supports two distinct semantics:

// Will return an instance that is shared across the app
Locatable(.sharedInstance) var service: Servicing

// Will return a new instance every time
Locatable(.newInstance) var service: Servicing

Requirements

Xcode 11+ & Swift 5.1

Installation

CocoaPods

Add the following to your Podfile:

pod "Locatable"

Carthage

Add the following to your Cartfile:

github "vincent-pradeilles/locatable"

Author