LazyLoader - a simple, thread-safe class that can be used to load data on demand.

/ Published in: C#
Save to your folder(s)

A simple, thread-safe wrapper class for lazy-loading data into an instance on-demand (i.e. when the instance is first accessed.)


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:

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.