How have the new features of C# changed your code?

March 31st, 2008

Here is a simplified example of how the functional programming style of Linq has impacted the way I would do a DDD service implementation.

Before:

IEnumerable<TDomainEntity> domainEntities = Repository.Find(criteria);
IEnumerable<TDto> dtos = Assembler.DomainToService(domainEntities);
return new List<TDto>(dtos);
After:
return Repository
           .Find(criteria)
           .ToList()
           .ConvertAll<TDto>(Assembler.DomainToService);
Thoughts? Samples? WTF’s?

Jarod Ferguson Uncategorized , ,

  1. Steve
    March 31st, 2008 at 02:55 | #1

    return Repository.Find(criteria).Select(Assembler.DomainToService).ToList();

    Even easier ;)

  2. March 31st, 2008 at 15:28 | #2

    Ah yes, very nice!

Comments are closed.