Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Implement self-resolution capability for the IoC container #10

Open
@castarco

Description

@castarco

Problem description:

In some circumstances, the resolved objects might "need" to hold a reference to the IoC container itself, so they can use it later to resolve other objects during their lifetime, as if it was an injected factory.

Right now, this is only possible if we perform an explicit registration of the container itself, and this has the drawback of "fixing" its type for all possible future resolutions.

This forces us to register the container as late as possible, and could not be enough in case we need to use it from different registered dependencies, so we might have to register it many times with different keys. That's clearly suboptimal from a usability perspective.

Proposed solution:

  1. Reserve the string $ to identify the container itself.
    • When used during resolution, the container itself has to be returned
    • It has to be impossible to register other dependencies using $ as key.
  2. The type of the resolved value for the key $ changes every time we register a new dependency, to avoid having a "fixed" type that doesn't account for all the introduced changes in the container.

Status

  • direct self-resolution: Implemented in Self resolution #11
  • indirect self-resolution (the runtime support is there, but types have to be tweaked): Implemented in Implement basic indirect self-resolution #12
  • make it possible to have constructors that depend on indirect self-resolution AND "typical" resolution at the same time.
  • add support to singleton resolution

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions