I would wrap this in a reusable extension method, for example:
public static OrderDTO ToDto(this Order from) { return new OrderDTO { Name = from.Name, Customer = from.ConvertTo<CustomerDTO>(), Items = from.Items.Map(x => x.ConvertTo<ItemDTO>()).ToArray(), } }
which can then be called up whenever you need to match DTO orders, for example:
return order.ToDto();
A few more examples of ServiceStack Auto-matching are available on the wiki .
The ServiceStack service side is if your mapping requires more than the standard default behavior that is output from the automated mapper, then you should wrap it with the DRY extension method so that the extensions and settings needed for your mapping are clear and easy supported in code. This is recommended for many things in ServiceStack, for example. Maintain non-standard and complex IOC binding in code, rather than rely on the unclear heavy function of IOC.
If you prefer this, you can, of course, adopt a third-party tool such as AutoMapper.
mythz source share