square / Cleanse

Lightweight Swift Dependency Injection Framework
Other
1.78k stars 90 forks source link

Refactoring improvements for Resolver. #159

Closed sebastianv1 closed 4 years ago

sebastianv1 commented 4 years ago

Cleanse has a type of one-to-many mapping for a given dependency to how it can be used within the object graph. For a given Type, it can be represented as Provider<Type>, WeakProvider<Type>, or () -> Type. Currently we support this by adding each of these types into the object graph dictionary for key lookup during dependency resolution. However, for other resolution steps (i.e duplicate binding, cyclical dependencies), we filter these types out so that we don't over-report errors or run into false-positive. The TypeKey helps normalize the types we see in the graph so that we don't have to unnecessarily add and filter certain types during resolution.

Most steps are just static functions with the primary operating type passed in as a parameter. We can make this a bit more "swifty" by moving the code into an extension on these types.