Closed ilyapuchka closed 8 years ago
After closer look I noticed a problem with definitions with runtime arguments. For them if auto-wiring fails validate method can ask calling site to provide some arguments passing a key under test:
container.validate() //will only try auto-wiring
container.validate() { key in
if key.argumentsType == String.self { return "test string" }
return nil
}
But that does not look very clean. Another option could be to have and argument of array of arguments that will be matched with required arguments type during validation:
validate(withArguments: ["test string", (1, 2)])
Validate method should accumulate only DipError
, because if for some factory arguments are not valid it can throw some other error. It should not fail validation. But it could prevent further testing of current definition.
On the other hand with TDD such validation method does not make a lot of sense because there will be test for each configuration that will just use register-resolve api.
For tests it could be useful to be able to validate container configuration just with one call, that will check if everything what is registered in the container can be resolved. This method should iterate all definitions and collect all the errors thrown by
resolve
. Depends on #75 because when iterating definition we can not know their types at compile time.