I am working on a Prism desktop application and would like to know the best way to deal with lookup / reference data lists when using a WCF backend. I think this question may cover a few areas and I would appreciate some guidance
For example, consider a lookup that contains Products(codes and descriptions) which would be used in a lot of different input screens in the system.
- Does the viewmodel call the WCF service directly to obtain the data to fill the control?
- Would you create a control that solely deals with Products with its own viewmodel etc and then use that in every place that needs a product lookup or would you re-implements say a combobox that repopulates the products ItemsSource in every single form view model that uses it?
- Would I create a brand new WCF service called something like LookupData service and use that to populate my lookup lists? – I am concerned I will end up with lots of lookups if I do this.
- What other approaches are there for going about this?
I suggest creating your lookup object/component as a proxy object for WCF service. It can work in several ways, but most simple coming to my mind would be:
Productsentities and requested one (eg. basing on product code)ProductsProviderProductsProvider(eg. via constructor injection)Key element in this model is
ProductsProvider– it will work as kind of cache forProductsobjects. First, it will ask web service for all products (or some part of it, up to your liking) to start with. Then, whenever you need to lookup product, you ask provider – it’s provider’s responsibility to deal with how product should be looked up – maybe it’s already in local list? Maybe it will need to call web service for update? Example:Now, what this gives you is:
ProductsProviderinstanceEdit:
As for your second question. Control may not be needed, but having view model for
Productentity is definitely a good idea.