Simple service locator infrastructure for swift

Related tags

JSON ServiceLocator
Overview

CoreSwift Locks CoreSwift Locks

badge-languages badge-platforms badge-license badge-ci


ServiceLocator

Simple service locator infrastructure. Pass around protocols backed by these locators to your view controllers and coordinators to simplify dependency injection.

Basic Example

/// Services available in the app scope.
protocol AppServices {
  var myAppScopedService: MyAppScopedServiceProtocol { get }
  var otherAppScopedService: OtherAppScopedServiceProtocol { get }
}

/// Production implementation of `AppServices`.
class ProdAppServices: ServiceLocator, AppServices {
  var myAppScopedService: MyAppScopedServiceProtocol {
    singleton { MyAppScopedServiceImpl(other: otherAppScopedService) }
  }
  
  var otherAppScopedService: OtherAppScopedServiceProtocol {
    singleton { OtherAppScopedServiceImpl() }
  }
}

Scopes

Compose service locators to provide isolation amongst domains.

Scopes

Broad Rules

  • Parent scopes must not access services from child scopes
  • Child scopes can access services from parent scopes
  • Child scopes must not access services/data from sibling scopes

Example

/// Services available in the user scope.
protocol UserServices {
  var myUserScopedService: MyUserScopedServiceProtocol { get }
}

/// Production implementation of `UserServices`.
class ProdUserServices: ChildServiceLocator<ProdAppServices>, UserServices {
  var myUserScopedService: MyUserScopedServiceProtocol {
    singleton {
      UserScopedServiceImplementation(parentService: parent.myAppScopedService)
    }
  }
}
You might also like...
Command line tool written in Swift dedicated to perform Mutation Testing of your Swift project

Mutanus Command line tool written in Swift dedicated to perform Mutation Testing of your Swift project. Inspired by Muter Usage mutanus -c path-to-co

Swift-json - High-performance json parsing in swift

json 0.1.4 swift-json is a pure-Swift JSON parsing library designed for high-per

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs

Codable code is a Swift Package that allows you to convert JSON Strings into Swift structs.

Implement dynamic JSON decoding within the constraints of Swift's sound type system by working on top of Swift's Codable implementations.

DynamicCodableKit DynamicCodableKit helps you to implement dynamic JSON decoding within the constraints of Swift's sound type system by working on top

AlamofireObjectMappe - An Alamofire extension which converts JSON response data into swift objects using ObjectMapper

AlamofireObjectMapper An extension to Alamofire which automatically converts JSON response data into swift objects using ObjectMapper. Usage Given a U

Freddy - A reusable framework for parsing JSON in Swift.
Freddy - A reusable framework for parsing JSON in Swift.

Why Freddy? Parsing JSON elegantly and safely can be hard, but Freddy is here to help. Freddy is a reusable framework for parsing JSON in Swift. It ha

[Deprecated] A shiny JSON parsing library in Swift :sparkles: Loved by many from 2015-2021
[Deprecated] A shiny JSON parsing library in Swift :sparkles: Loved by many from 2015-2021

🚨 Deprecation Notice 🚨 Gloss has been deprecated in favor of Swift's Codable framework. The existing Gloss source is not going away, however updates

HandyJSON is a framework written in Swift which to make converting model objects to and from JSON easy on iOS.

HandyJSON To deal with crash on iOS 14 beta4 please try version 5.0.3-beta HandyJSON is a framework written in Swift which to make converting model ob

Himotoki (紐解き) is a type-safe JSON decoding library written purely in Swift.

Himotoki Himotoki (紐解き) is a type-safe JSON decoding library written purely in Swift. This library is highly inspired by the popular Swift JSON parsin

Owner
CoreSwift
CoreSwift
Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling.

Decodable Simple and strict, yet powerful object mapping made possible by Swift 2's error handling. Greatly inspired by Argo, but without a bizillion

Johannes Lund 1k Jul 15, 2022
Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable

Elevate is a JSON parsing framework that leverages Swift to make parsing simple, reliable and composable. Elevate should no longer be used for

Nike Inc. 611 Oct 23, 2022
An extremely simple JSON helper written in Swift.

Alexander Alexander is an extremely simple JSON helper written in Swift. It brings type safety and Foundation helpers to the cumbersome task of JSON u

HODINKEE 36 Sep 15, 2022
A Simple Alert For Swift

JoeSimpleAlert Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation Joe

null 0 Nov 30, 2021
Simple JSON Object mapping written in Swift

ObjectMapper ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Tristan Himmelman 9k Jan 2, 2023
A simple solution to show a toast message by writing single one line of code

easySwiftToast A very simple solution to show a toast message by writing single one line of code. Installation easySwiftToast is available through Coc

wajeehulhassan 7 May 13, 2022
A simple educational application for the game Connect Four for two players

Connect4Game A simple educational application for the game Connect Four for two players. The algorithm checks the match of 4 tiles horizontally, verti

NIKOLAY NIKITIN 0 Oct 20, 2022
Simple implementation of asset management app UI using swiftUI

MyAssets (자산관리 앱 만들기) swiftUI를 이용하여 자산관리 앱 UI를 간략하게 구현 (swiftUI를 익히기 위함) 초기 화면 1. Tab bar 구현 자산, 추천, 알람, 설정 탭 구현 2. Navigation bar 구현 1) leading에 titl

null 0 Dec 9, 2021
Simple and Elegant Range(A,B) to Range(P,Q) mapper in less then five lines of code.

HSRange Description HSRangeConvertor Simple and Elegant Range[A,B] to Range[P,Q] mapper in less then three lines of code. E.g. Suppose we have Range[1

Hitendra Hckr 10 Sep 29, 2021
JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift.

JSEN /ˈdʒeɪsən/ JAY-sən JSEN (JSON Swift Enum Notation) is a lightweight enum representation of a JSON, written in Swift. A JSON, as defined in the EC

Roger Oba 8 Nov 22, 2022