Tag Archives: loading data

(C#) LazyLoader – a simple, thread-safe class that can be used to load data on demand

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();

Posted in C# | Also tagged , , , , , , , , | Leave a comment