Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest creating your lookup object/component as a <a href="http://en.wikipedia.org/wiki/Proxy_pattern" rel="nofollow">proxy</a> object for WCF service. It can work in several ways, but most simple coming to my mind would be:</p> <ol> <li>Implement WCF service with methods to provide <strong>all</strong> <code>Products</code> entities and requested one (eg. basing on product code)</li> <li>Implement component that will use WCF client to get products, let's call it <code>ProductsProvider</code></li> <li>Your view models will take dependency on <code>ProductsProvider</code> (eg. via <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow">constructor injection</a>)</li> </ol> <p>Key element in this model is <code>ProductsProvider</code> - it will work as kind of cache for <code>Products</code> objects. 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 <em>looked up</em> - maybe it's already in local list? Maybe it will need to call web service for update? Example:</p> <pre><code>public class ProductsProvider { private IList&lt;Product&gt; products; private IProductsService serviceClient; public ProductsProvider(IProductsService serviceClient) { this.serviceClient = serviceClient; this.products = serviceClient.GetAllProducts(); } public Product LookUpProduct(string code) { // 1: check if our local list contains product with given code // 2: if it does not, call this.serviceClient.LookUpProduct // 3: if service also doesn't know such product: // throw, return null, report error } } </code></pre> <p>Now, what this gives you is:</p> <ul> <li>you only need to have <strong>one</strong> <code>ProductsProvider</code> instance</li> <li>better flexibility with when and how your service is called</li> <li>your view models won't have to deal with WCF at all</li> </ul> <p><strong>Edit:</strong></p> <p>As for your second question. Control may not be needed, but having view model for <code>Product</code> entity is definitely a good idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload