Skip to content

Introducing reflection info injection process #308

@ENikS

Description

@ENikS

Injection info

Reflection allows discovery of metadata for all kinds of elements in the system. Unity is introducing new design with ability to reflect on injected data

Legacy Implementation

Original design relied on resolver policies and delegates to provide injected values. This method does not provide any information about what is being injected to the container.

At runtime the container would call resolver method on the injected member to obtain the value and perform all kinds of magic to implement overrides and build pipelines. This design required a lot of runtime reflection and created unnecessary overhead.
Even constant values injected into registrations would still be retrieved via resolver calls and would only be available at resolution stage.

Injection Reflection

Unity is introducing a new method to query injected members about what data is injected. It allows to analyze injections at the pipeline build stage and eliminate unnecessary resolvers and expensive runtime reflection.

The injection member provides the following information:

  • Contract of the injected import
  • Is this import optional
  • What kind of data it injects, if any

The injected data is categorized into the following:

  • Resolver delegate (same old delegate as before)
  • Value
  • None

When resolver delegate is returned by the query, Unity performs the same song and dance as before. It will call the delegate and get the value.

If None is returned by the query, Unity resolves value from the container using the Contract injector requires.

Obviously, the Value just used as is and returned immediately without any overhead.

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