A simple dependency factory library
import DependencyFactory
protocol StorageServiceProtocol: BaseService {
var token: String? { get set }
}
class StorageService: BaseService, StorageServiceProtocol {
@Stored(key: "Token", in: .keychain) var token: String?
}
import DependencyFactory
extension Container {
static var storage: Factory<StorageServiceProtocol> {
Factory(self) { StorageService() }
}
}
class ViewModel: BaseViewModel {
@Injected(\.storage) var storage
}
class MemoryStorageService: BaseService, StorageServiceProtocol {
var token: String?
}
Container.shared.manager.register { () -> StorageServiceProtocol in
MemoryStorageService()
}