/ Published in: C#
A simple, thread-safe wrapper class for lazy-loading data into an instance on-demand (i.e. when the instance is first accessed.)
Usage:
LazyLoader l = new LazyLoader(() => Foo.LoadFromDataSource("DB Connection String"));
// For access to the lazy-loaded instance:
var x = l.Instance.Bar;
// Need to ensure that the data is loaded deterministically? Use this:
l.EnsureLoad();
Usage:
LazyLoader l = new LazyLoader(() => Foo.LoadFromDataSource("DB Connection String"));
// For access to the lazy-loaded instance:
var x = l.Instance.Bar;
// Need to ensure that the data is loaded deterministically? Use this:
l.EnsureLoad();