DIKit icon indicating copy to clipboard operation
DIKit copied to clipboard

@OptionalInject does not work with actual optional

Open bgeerdes opened this issue 3 years ago • 0 comments

The @OptionalInject wrapper only works if one provides a non-optional component. If the component is optional, the @OptionalInject wrapped instance always ends up nil.

This appears to be because the component is registered using its optional type (e.g. Optional<ComponentF>) but then the resolve fails as it is looking for non-optional type (e.g. ComponentF).

This can be demonstrated in DIKitTests testOptionalInjection by making ComponentF's init optional.

optional_init

Doing this causes the test to fail.

bgeerdes avatar Nov 23 '20 15:11 bgeerdes