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

  1.  
  • Posted by on January 1st, 1970
This entry was posted in C# and tagged , , , , , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?