English 中文(简体)
更新物体模型建设以适应同步数据单
原标题:redoing object model construction to fit with asynchronous data fetching

I have a modeled a set of objects that correspond with some real world concepts.

TradeDrug, GenericDrug, TradePackage, DrugForm

Underlying the simple object model I am trying to provide is a complex medical terminology that uses numeric codes to represent relationships and concepts, all accessible via a REST service - I am trying to hide away some of that complexity with an object wrapper.

举一个具体的例子

我可以呼吁

TradeDrug d = Searcher.FindTradeDrug("Zoloft")    or
TradeDrug d = new TradeDrug(34)  

where 34 might be the code for Zoloft. This will consult a remote server to find out some details about Zoloft. I might then call

GenericDrug generic = d.EquivalentGeneric()
System.Out.WriteLine(generic.ActiveIngredient().Name)

in order to get back the generic drug sertraline as an object (again via a background REST call to the remote server that has all these drug details), and then perhaps find its ingredient.

This model works fine and is being used in some applications that involve data processing.

Recently however I wanted to do a silverlight application that used and displayed these objects. The silverlight environment only allows asynchronous REST/web service calls. I have no problems with how to make the asychhronous calls - but I am having trouble with what the design should be for my object construction.

Currently the constructors for my objects do some REST calls sychronously.

 public TradeDrug(int code)
 {
     form = restclient.FetchForm(code)
     name = restclient.FetchName(code)
     etc..
 }

If I have to use async events or actions in order to use the Silverlight web client (I know silverlight can be forced to be a synchronous client but I am interested in asychronous approaches), does anyone have an guidance or best practice for how to structure my objects.

我可以向施工者发出行动反馈。

 public TradeDrug(int code, Action<TradeDrug> constructCompleted)
 {

 }

but this then allows the user to have a TradeDrug object instance before what I want to construct is actually finished. It also doesn t support an event async pattern because the object doesn t exist to add the event to until it is constructed.

Extending that approach might be a factory object that itself has an asynchronous interface to objects

 factory.GetTradeDrugAsync(code, completedaction)

或者与“公平贸易”活动有关?

Does anyone have any recommendations? Does anyone know how the new Reactive framework might fit in with any solution?

最佳回答

我将 d弄公共建筑商,并采用合成工厂方法。 它不一定是一个单独的工厂目标,它只能是静态的贸易方法,例如:

public static void LoadByIdAsync(int id) { ... }
public static void LoadByIdAsync(int id, object userState) { ... }
public static event LoadByIdCompletedEventHandler LoadByIdCompleted;

The event-based async patterns is presented here: http://msdn.microsoft.com/en-us/library/wewwwwczdw.aspx

问题回答

暂无回答




相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签