Aside from registered dependencies, are dependencies that are determined through reflection, such as injected dependencies, done in regards to the lifetime of the dependency or during the lifetime of the DI Container?
Edit: DI Container in mind is Unity.
Edit: Elaboration: I am curious how many times the reflection process occurs, and also wanted clarity regarding weather or not the stage in the Unity build that uses reflection will find constructors and properties. The fourth stage in the Unity build, according to the MSDN ( Source ), is “Precreation” being the “Fourth stage. Reflection over constructors, properties, etc. is performed here.” How many times is this stage run? Once during the construction of the container, or every time constructor and property dependencies need to be resolved? Which part of the Register Resolve Release pattern does this occur in?
Unity uses a build pipeline called
StrategyChainto create objects. This pipeline is run every time you resolve an object from the container.Each step in that pipeline is implemented as a strategy. These strategies lookup values called
BuilderPolicies. These policies encapsulate information a strategy has accumulated (like using reflection to determine which constructor to use, which properties to inject etc.). The first time you run the pipeline for a specific type the strategies put policies into a store calledPolicyList. The next time the pipeline is asked to build that type those values will be reused so the effort involved should only cost you once.UPDATE
I guess you mean ASP.NET? Actually there are two
PolicyLists. One which only lives for one cycle through theStrategyChain(transient) and one which is coupled to the lifetime of the container. It lives as long as your instance of theUnityContaineris not disposed or garbage collected. One thing that might be interesting to you: You can’t serialize your container. Thus you can’t tell an application running on a web farm to store it in a cache and share it between servers.