This PR contains the work that implements the Dependency service, which is used as a dependency injection mechanism in the application. To give further details on what was done: - [x] created the `Dependency` library into the **Libraries** package; - [x] defined the `DependencyKey` protocol; - [x] implemented the `DependencyService` service; - [x] implemented the `Dependency` property wrapper. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: rock-n-code/deep-linking-assignment#6
35 lines
670 B
Swift
35 lines
670 B
Swift
//
|
|
// TestServices.swift
|
|
// DependencyTests
|
|
//
|
|
// Created by Javier Cicchelli on 11/04/2023.
|
|
// Copyright © 2023 Röck+Cöde. All rights reserved.
|
|
//
|
|
|
|
import Dependency
|
|
|
|
// MARK: - Protocols
|
|
|
|
protocol TestService {}
|
|
|
|
// MARK: - Services
|
|
|
|
struct SomeService: TestService, Equatable {}
|
|
struct SomeOtherService: TestService, Equatable {}
|
|
|
|
// MARK: - DependencyKey
|
|
|
|
struct TestServiceKey: DependencyKey {
|
|
static var currentValue: TestService = SomeService()
|
|
}
|
|
|
|
// MARK: - DependencyService+Keys
|
|
|
|
extension DependencyService {
|
|
var testService: TestService {
|
|
get { Self[TestServiceKey.self] }
|
|
set { Self[TestServiceKey.self] = newValue }
|
|
}
|
|
}
|
|
|