Hello,
It is possible to do something like this, where the argument passed to the dependency container when trying to resolve a dependency is typed as a protocol?
protocol ArgumentType {}
struct Dependency {}
let container = Container()
container.register(Dependency.self) { (container: ResolverType, argument: ArgumentType) in
return Dependency()
}
extension String: ArgumentType {}
let dependency = container.resolve(Dependency.self, argument: "I’m the argument!")
This fails to find the registered dependency, this way. If I change the registration to specify String as the argument type, instead of ArgumentType:
container.register(Dependency.self) { (container: ResolverType, argument: String) in
return Dependency()
}
Then it resolves as expected.
Please advise – thank you!
OK, figured it out. This works so long as you do:
let dependency = container.resolve(Dependency.self, argument: "I’m the argument!" as ArgumentType)
Most helpful comment
OK, figured it out. This works so long as you do: