-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInjector.swift
More file actions
43 lines (32 loc) · 878 Bytes
/
Injector.swift
File metadata and controls
43 lines (32 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// Injector.swift
// FirebaseChatApp
//
// Created by Amisha Italiya on 29/11/24.
//
import Swinject
public class Injector {
fileprivate var appAssembler: Assembler!
private init() {}
public static let shared = Injector()
public func initInjector() {
appAssembler = Assembler([AppAssembly()])
}
public func setTestAssembler(assemblies: [Assembly]) {
appAssembler = Assembler(assemblies)
}
}
public func appResolve<S>(serviceType: S.Type) -> S {
Injector.shared.appAssembler.resolver.resolve(serviceType)!
}
@propertyWrapper
public struct Inject<Component> {
private var component: Component
public init() {
self.component = appResolve(serviceType: Component.self)
}
public var wrappedValue: Component {
get { return component}
mutating set { component = newValue }
}
}