Replies: 1 comment 1 reply
-
Please read the documentation again as you appear to have the concept backwards. https://hmlongco.github.io/Factory/documentation/factory/contexts/#-onArg Now consider: import Foundation
import Factory
extension Container: AutoRegistering {
public func autoRegister() {
#if DEBUG
myServiceType
.onArg("mock0") { EmptyService() }
.onArg("mock1") { MockServiceN(1) }
.onArg("error") { MockError(404) }
#endif
}
} When resolved during a specific application launch, myServiceType can only resolve to a single instance, and onArg can be used to decide which service factory to resolve based on the launch argument passed. let app = XCUIApplication()
app.launchArguments.append("mock0")
app.launch()
// test Which results in myServiceType resolving to EmptyService() when needed. If you want to test using mock1, you need to relaunch the application again using that parameter. let app = XCUIApplication()
app.launchArguments.append("mock1")
app.launch()
// test Which results in myServiceType resolving to MockServiceN(1) when needed. That being the case, doing the following is nonsensical. let app = XCUIApplication()
app.launchArguments.append("mock0")
app.launchArguments.append("mock1")
app.launchArguments.append("error")
app.launch()
// test Which service should be chosen? There can be only one, but you're basically telling the app to run in three different modes at the same time. Which means that having the types be arrays or dictionaries doesn't matter. Order doesn't matter. What matters is the existence of the passed (or runtime) parameter during factory resolution. |
Beta Was this translation helpful? Give feedback.
-
Arguments and runtimeArguments are Array and Dictionary types, respectively.
Therefore, both can be managed with multiple values rather than a single value.
but at the time of resolution, even if developers manage multiple values, in the "FactoryForCurrentContext of FactoryOptions", arguments will always check the same value first, and runtimeArguments will check random values because no order is guaranteed.
I expected to be able to freely manipulate the test environment by putting various values in arguments & runtimeArguments, but I found it impossible when I looked at the factoryForCurrentContext internal logic of FactoryOptions.
Developers can't deploy multiple test environments at once and freely switch, so why is it defined as Array, Dictionary Type?
Beta Was this translation helpful? Give feedback.
All reactions