An expresion always gets a an
IExpressionContext from which it can extract information to evaluate. A product will generally encounter this when working with Delegate Expression.
The context contains zero or more objects that an evaluator can access with
TryGetIntance. For example,
MetaPropertyExpression looks for an
IMetaObject using this method.
TryGetInstance method accesses objects that have been added to the context. How, then, can an evaluator get a singleton from the IOC?
One obvious way of getting to singletons is to inject them into the code that creates the evaluator and then included it in the evaluator.
Another, more convenient way, is to call
TryGetSingle on the context itself. This method finds an IOC in the context and then gets the requested type from there. The method returns false if there is no IOC in the context.
If there is an IOC, but the requested object is not registered, then the call crashes, just as any other failed call to
GetInstance() would. That is, the call is safe to call on an empty context, but will crash if the evaluator tries to use an unregistered singleton.
See the chapter on the IOC for more information.