Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle Dtos for objects which implement multiple interfaces?
    primarykey
    data
    text
    <p>We are using Dtos in our WCF service interface, but have started to come across issues when the Business Object that the Dto represents implements more than a single interface and we want to return the Dtos in those different contexts and to also be able to treat the Dtos polymorphically on the client.</p> <p>For example lets say we have an interface for an <code>IBusinessObject</code> with several properties containing details of the relationships of the object, attributes of the object etc etc. I have several implementations of this one being a <code>LinearBusinessObject</code> which implement <code>IBusinessObject</code> and <code>ILinear</code>. There are other implementations of <code>ILinear</code> which are not also business objects, just simple linear things. </p> <p>Our service has a method to get a business object. This returns a base Dto class (<code>BusinessObjectDto</code>) which declares the common parts of a <code>IBusinessObject</code> (relationships attributes etc) and the <code>LinearBusinessObjectDto</code> which extends <code>BusinessObjectDto</code> and adds the extra information about the linear side of things. This is fine and enables the client to treat the returned <code>BusinessObjects</code> with some degree of polymorphism.</p> <p>We also want a method which gets a Linear thing. This returns a base class <code>LinearDto</code> which contains the common linear details. The simple linear object implementation extend <code>LinearDto</code> and all is good. But now I have a problem, as I can't have my <code>LinearBusinessObjectDto</code>extend from both <code>LinearDto</code> and and <code>BusinessObjectDto</code> as only single inheritance is supported, and I can't use interfaces as WCF doesn't know what types to then put in the service contract definitions in the WDSL.</p> <p>So I've started having 2 dtos for my <code>LinearBusinessObject</code>, one which derives from <code>BusinessObjectDto</code> (<code>LinearBusinessObjectAsBusinessObjectDto</code>) and one which derives from LinearDto (<code>LinearBusinessObjectAsLinearDto</code>) and then converting each one based on the interface I'm interested in. </p> <p>This seems like its going to result in many extra Dto classes (of which I already have many) and so I'm wondering if there is a better solution than this? Or is this just something we have to live with?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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