How to tell if business object was created/fetched async?

How to tell if business object was created/fetched async?

Old forum URL: forums.lhotka.net/forums/t/11529.aspx


jhardman posted on Tuesday, August 14, 2012

Is there a way to tell if an editable business object was created/fetched async?  I am looking into the idea of lazy loading child lists async or sync depending on how the business object was instantiated.  At first I thought of using a similar method as running business runs async or sync:

        if (System.Web.HttpContext.Current != null)
          IsAsync = false;
        else
          IsAsync = true;

However the problem with this logic is that if running in web context then it is sync.  What about running in Windows Service?  I can't wait for the lazy loaded child collection to return at some point in the future and set its property since there are no UI bindings.

RockfordLhotka replied on Tuesday, August 14, 2012

You would need to pass that bit of info via a criteria object. Or in ClientContext. There is no automatically passed vale that tells the server side code that the client did an async call.

jhardman replied on Wednesday, August 15, 2012

Thanks, I was hoping there may have been a way with DataPortal.BeginFetch to raise an event or call a method in the business object that I could override.

I have never used ClientContext and don't know what it is or what it does. Can you point me in the right direction or which ebook covers it?

JonnyBee replied on Wednesday, August 15, 2012

I think this should rather be a config setting on the client as to whether client data access/lazy load child  should be async or sync. 

I don't like the ideat that the object itself must keep track of how it was created from the client. 

Remember, with the new async/await keywords in .NET 4.5/4.0 you can also use async data portal / data access in ASP.NET application and WCF services.

JonnyBee replied on Wednesday, August 15, 2012

Then there's also at least 2 different types of async:

  1. The client makes an async DataPortal.XYZAsync call to a sync DataAccess 
  2. The DataAccess is async, ex: DataPortal_XYZ methods in the BO return a Task<T> (no matter if the client did a sync or async call)

(This is all similar to how WCF 4.5 client and server works too!)

Copyright (c) Marimer LLC