Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 13th, 2006, 05:39 PM
Authorized User
 
Join Date: Nov 2006
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object Factories with Lazy Loading in C#

I'm looking for a lazy loading solution in c#.

The idea is, to have a kind of object factory, which will be responsible for creating my entity objects.
When a property of such an object is accesed and it is not yet loaded, the factory
(or a magic watcher) will be able to pause the execution flow for a while (maybe that step is not necessary)
load the missing data (don't know how to specify, from where to load that data----maybe via attributes) and
return to the flow.

My entity objects, do not have a possibility to load the missing data by themselves, because they
are only data containers having private members, which are accessible via public properties.
These objects need to be filled with their data from outside, and therefore many lazy loading solutions
won't work here.

Maybe anyone of you knows the solution for my problem?

Thank You in advance!


Greetz!

 cyberjoe

Reply With Quote
  #2 (permalink)  
Old December 13th, 2006, 09:39 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are lots of ways to accomplish this.

The class of a member object can be in charge of loading an instance of itself via a static method. This is known as a factory method.

You can also code up a factory class or set of classes whose task it is to provide objects as you describe via factory methods.

Another popular pattern is the Abstract Factory - but your description of what you need doesn't match this pattern as far as it looks to me.

One important question that should be addressed is regarding your architecture: Are you remoting anything? Are objects being created on one machine and transported to another? That comes in to play because you will need to make sure your objects are serializable if you want to take advantage of the .NET marshal by value feature.

It might be useful for you to look up Rocky Lhotkas CSLA books. There are versions for C# and VB.NET published by Apress (as well as the older VB6 books that were published by Wrox)

Woody Z
http://www.learntoprogramnow.com
Reply With Quote
  #3 (permalink)  
Old December 13th, 2006, 11:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , USA.
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

 
Quote:
quote:My entity objects, do not have a possibility to load the missing data by themselves, because they are only data containers having private members, which are accessible via public properties. These objects need to be filled with their data from outside...


You could invoke a static factory method in the property accessor itself.

Say, for example, the property you want to load is a child collection declared in your object as:

Code:
ChildCollection _myChildCollection = null;
You could load this data member upon accessing the property by doing something like:

Code:
public ChildCollection MyChildCollection { 
 get { 
   if (_myChildCollection == null) {

      // Invoke static factory method defined in ChildCollection. 
     _myChildCollection = ChildCollection.GetChildCollection(this._id); 
   } 
   return _myChildCollection; 
 } 
}




Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Over-using Lazy properties in GridView? kalel_4444 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 November 5th, 2008 01:43 AM
Lazy Load... Cool but... pbernardo01 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 7 December 28th, 2007 02:00 AM
Error in loading the serialized canvas object Dhruv_er16 Windows Presentation Foundation 0 May 23rd, 2007 08:04 AM
Is the Internet making programmers lazy? dparsons Intro Programming 12 April 8th, 2007 10:45 AM



All times are GMT -4. The time now is 05:24 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.