Search code examples
dependency-injectioncdihk2

What exactly does "reify" mean in the context of dependency injection


I've read a few books on different DI frameworks, and I see the term "reify" or "reified" (past tense) thrown around, but I can't get a firm grasp on what that actually means code-wise.

The wikipedia definition states

make (something abstract) more concrete or real.

I've also read What do “reify” and “reification” mean in the context of (functional?) programming?, which kind of confirms the above definition in a programming context.

But I can't get a picture in my head of how this applies in code (in the context of DI). The reason for the question is that I am trying to debug a stacktrace by looking at some HK2 source code, and I see variables/methods such as reified and snippets like if (!reified).

So I would like to get a code example of when something is not reified and when/how it becomes reified, and maybe a little better explanation of how the above definition applies in the context of DI.

Note: Though the question is tagged and , I imagine this question could be answered by anyone knowledgeable in DI, as I don't think the term is strictly tied to Java DI. I have seen the term used in a book on Ninject (a C# framework).


Solution

  • In HK2 the term reify is specifically about whether or not an ActiveDescriptor has been classloaded yet.

    All services in HK2 have an associated ActiveDescriptor that contains information about the service. Some information is available about the service before the class associated with the service is classloaded (such as the service contracts and qualifiers, in string form). Some information about the service is only known after the service is classloaded and then analyzed (reified). For example, the qualifiers can then be inspected for matching fields, and the actual set of injection points can be found.

    Prior to the class being loaded and analyzed the ActiveDesctiptor is said to NOT be reified. After the class has been loaded and analyzed the ActiveDesctiptor is said to be reified.

    Because HK2 is very sensitive to things like startup time it tends to try to keep ActiveDesciptors NOT reified for as long as it can, reducing the burden on the classloader lock