views:

287

answers:

2
+2  Q: 

WCF Layers

Hi

I recently started with WCF ( yeah I know I am behind :-) ). The question is how I must structure it.

I am used to DAL,BL and Presentation Layer. I am replacing( sort of) my DAL with entity framework.

So I have this so far

DAL(entity framwork) --> BL --> contracts (datacontract messagecontrol service contract behaviours etc) --> service implementation --> client.

The question is there a layer between bl and the contracts that converts( lack of a better word) the bl into the data contract.

Ex DAL.Customer(Entity Framework) --> BL (Rules) -- > Converter (Just converting) --> Contracts.Customer

OR

DAL.Customer(Entity Framework) --> BL (Rules) -- > Converter (Calling BL and converting. converter implementing service contract) --> Contracts.Customer.

thanks

+1  A: 

There should be a thin "layer", simply because you don't really need the BL layer to understand your contracts, and you don't really want to expose your BL objects as contracts to the rest of the world.

Of course, you can do this. You can develop data contracts that are simple Data Transfer Objects. These would contain only data and no behavior, and would expose the portion of your data that you intend the world to see. Your BL could either limit itself to that model, or could inherit from it to add BL-specific features.

Alternatively, just have a BL-version of reality and a "Contract" version of reality and convert between them.

John Saunders
Thanks. I dont really want to expose my bl to the world and also not the whole bl is required from the contract point of view.I think the converting between them sounds like a acceptable idea.I am still playing with the idea of having the service implementation call a layer that calls the bl and convert and then return the contract version.This layer will implement the servicecontract
Pintac
A: 

A lot of times you'll see similarities between your BL and Contract types. You can use a few shortcuts to help you convert between types with the excellent AutoMapper. These kinds of tools can help that layer stay "thin".

Anderson Imes
Thanks. I will say 80% of the time the bl and datacontract will be the same. I would just like to split it know so in the future i can change it if need be.
Pintac