I've noticed that in examples of creating expensive objects, StructureMap can defer creation using the Lazy or Func types for an interface.
e.g.
Lazy<ITheExpensiveService>();
I understand that with Lazy the value property is the single point at which the expensive object is then created.
Is StructureMap doing something special here or just using features already in .NET?
And how does this relate to how Func works since this has nothing to do with lazy creation?
StructureMap is not doing anything special when using Lazy. When resolving lazy dependency it just doing something like this:
new Lazy<TPluginType>(() => container.GetInstance<TPluginType>()
And for func this:
() => container.GetInstance<TPluginType>()
So the only difference here is that lazy wraps func.
How does func differs from lazy?
When you create object of Lazy{T} you provide object factory method as func. So when you use lazy.Value on property Value getter functor that you provided in the constructor will be executed so in fact it uses func to defer initialization.