December 2019
Intermediate to advanced
346 pages
9h 8m
English
In this case, since the underlying object is not created, the initialization logic will run on every call to the Value property. This is helpful in scenarios where the construction logic depends on external factors such as an internet connection while calling the external service. If the internet goes down momentarily, then the initialization call will fail, but subsequent calls can return the data. By default, Lazy<T> will cache exceptions for all parameterized constructor implementations, but it will not cache exceptions for the parameter less constructor implementation.
Let's try to understand what happens when Lazy<T> initialization logic throws a random exception:
Read now
Unlock full access