Injecting externally resolved dependencies into DependencyValues #365
-
Hi, is there a way to inject an externally resolved dependency to the dependency values without having to create an empty implementation for it ? Problem: Actual solution:
Despite the fact i should avoid having multiple instances of "SomeModule" Is there any way to avoid the empty implementation ? it does not look very nice to me, but i didn't found a better solution for the moment. Can i have some help with this 🙏 What would you recommend me to do in this case ? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @PereAlmendro, I'm not sure I fully understand your problem, but it seems to me that you want to conform to just enum FOODependencyKey: TestDependencyKey {
static var testValue: any FOODependencyProtocol {
FooEmptyImplementation()
}
} (Aside: Even better if your Then in the entry point of your app you will prepare the live dependency: @main
struct EntryPoint: App {
init() {
prepareDependencies {
$0.fooDependency = FooLiveImplementation()
}
}
} |
Beta Was this translation helpful? Give feedback.
Hi @PereAlmendro, I'm not sure I fully understand your problem, but it seems to me that you want to conform to just
TestDependencyKey
, notDependencyKey
, that way you don't have to provide aliveValue
:(Aside: Even better if your
FooEmptyImplementation
invokesreportIssue
in every protocol requirement that way you will get test failures if you ever use it in tests.)Then in the entry point of your app you will prepare the live dependency: