0

I have four projects:
1. Business project that defines the business login of my project.
2. Service contract project that defines a contract interface and DTOs.
3. Service implementation project that defines an implementation to the service.
4. Web application with svc file that uses the service.

Theoretically:
A. The contract project should reference to no one.
B. The service implementation should reference the contract project and the domain.
C. The web application should reference only the contract and implementation project.

I have service like this:

AccoundData GetAccount(AccountTypeEnum type);

The problem is that AccountTypeEnum defined in the domain, so that the contract and the web application should have reference to the domain.. But this is what we are trying to prevent.. So how can I prevent from the contract of "knowing" the domain?

Naor
  • 23,465
  • 48
  • 152
  • 268
  • 3
    The WCF contract has methods operating on your domain objects - how could it **not know** the domain?!?!!? – marc_s Aug 24 '11 at 14:04
  • @marc_s: The contract is only an interface and not implementation. Results from the domain are stored on Data Transfer Objects. Therefore, why should the contract know the domain? and if it knows, you force the we projects know the domain too. – Naor Aug 24 '11 at 14:56

1 Answers1

2

In such case you contract must use different enum / DTO and your service implementation must translate between contract enum and domain enum.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • isn't there any other solution then creating DTO for each type between the communicate with the service?.. Doesn't it consider code duplication? whenever I change the enum - I'll have to change the enum's DTO. – Naor Aug 24 '11 at 15:23
  • If you want such strict separation you must put additional effort to your application. I'm not aware of tool for automatic DTO creation - DTO should be specific for operation needs so you must always do it yourselves. For enums you can probably create T4 template for their creation but it will be more complex then create them manually. If you don't want to put additional effort merge your contract project with your service implementation project. – Ladislav Mrnka Aug 24 '11 at 15:23
  • How can I create T4 templates for Enum DTO creation? I am trying to search on google but there is no info about T4 and Enums. – Naor Aug 24 '11 at 16:28
  • 1
    You must create template from scratch - it must go through assembly, find all Enums defined in that assembly and create DTOs or other enums for them. – Ladislav Mrnka Aug 24 '11 at 16:42