palasthotel / wind

dependency injection container in pure swift
9 stars 2 forks source link

Added a fallback when a component is registered with a wrong public interface. #10

Closed benboecker closed 6 years ago

mkernel commented 6 years ago

@benboecker great work! However falling back to UIApplication.shared.container may lead to the wrong container in a lot of cases:

That is indeed a Problem. We need to find the correct container from within our extensions on the component. The easiest way would be to add an associated object reference to the container - however that would break with the idea that an component has only access to the dependencies it really needs.

I would prefer a stricter way: the container should keep a static, weak-referencing list of all instantiated components together with the container instance it originated from. Then we can move your containerHasDependencyForType implementation to a static method on Container.

That solution keeps the "container-component-barrier" intact and solves the Problem.

You or me? :)