Skip to content

@OptionalInject does not work with actual optional #44

@bgeerdes

Description

@bgeerdes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions