BasicServiceLocator

0.0.3

Very BasicServiceLocator for Swift
iballan/BasicServiceLocator

What's New

0.0.3

2023-04-06T18:51:30Z

Expose init of BasicServiceLocator

BasicServiceLocator

Very BasicServiceLocator for Swift

Installation

CocoaPods

pod 'BasicServiceLocator'

Swift Package Manager

Once you have your Swift package set up, adding SwiftyTimber as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/iballan/BasicServiceLocator.git", .upToNextMajor(from: "0.0.3"))
]

USAGE

// Protocols
protocol ServiceA {}
protocol ServiceB {}

// Implementation
class ServiceAA: ServiceA {}
class ServiceBB: ServiceB {}

// Fake or Debug Implementation
class FakeServiceB: ServiceB{}

// Service Resolver and Container
let serviceLocator : ServiceLocator = BasicServiceLocator()

// Registering
serviceLocator.registerService(ServiceA.self, instance: ServiceAA())
serviceLocator.registerService(ServiceB.self) {
    #if DEBUG
        return FakeServiceB()
    #else
        return ServiceBB()
    #endif
}

// Fetching and using service
let serviceA = try? serviceLocator.getService(ServiceA.self)
let serviceB = try! serviceLocator.getService(ServiceB.self)

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Oct 17 2024 18:56:25 GMT-0900 (Hawaii-Aleutian Daylight Time)