Contract-First SOA: Designing Business Domain: WCF

First of all – you need to understand if you really need full-blown SOA.

SOA basically means that every operation is going through service that decouples our system from other system/s. In rare cases (in case application grows extra huge) – one part of system from another.

Will your application “talk” with any other application?

If not and you are just building monolith website, free your mind and cut that SOA bullcrap. Otherwise you will end up with useless abstraction layer.

That is the only way you can apply 2nd approach because you can’t decouple domain model completely without mapping it to something else.


In case there really is a need for SOA – we must encapsulate, hide from outer world our domain model. That means – there must be some kind of mapping from our model to DTOs.

Is there any article/tutorial that explains how to map AccountSummary DTO to FixedAccount/ SavingsAccount

Mapping itself isn’t complex idea. Here’s one simple way to map objects:

class AccountSummary{
  public string InterestingThing {get; set;}
  public string AnotherThing {get; set;}
}
class AccountSummaryMapper{
   public static Map(BankAccount a){
    return new AccountSummary{
        InterestingThing=a.SomethingSomething,
        AnotherThing=a.Something.Else.ToString()
      };
   }
}
var accountSummary=
  AccountSummaryMapper.Map(myBankAccount);

This might seem ineffective. Object-to-object mappers like Automapper can help. Go through tutorial, it should be good enough to get you going. Idea ain’t hard – you create Maps, tell Mapper about them on application start and then use Mapper to Map your objects by given configuration.


Also – think about mapping direction. Good object oriented code usually means that you either ask questions or tell object to do stuff. Objects shouldn’t know about inner workings of other object responsibilities.

In analogy – it is bad for parents to complete their child homework because child won’t learn anything and parent will be burdened with unnecessary work. Instead – parent should force child to work on his own.

Mapping AccountSummary directly to BankAccount and re-setting its state is like doing homework. There shouldn’t be need for such a mapping. Instead – tell BankAccount to BankAccount.DoHomework(pencil, copybook, someStrongWords).


develop the business domain

You do not develop business domain. You develop domain model which is just a reflection of business domain, made to solve particular problems.

Leave a Comment