Andrew
Andrew

Reputation: 59

Pattern Help: Passing Object from DAL to Contract. Two Classes, One Interface

I have many projects in my solution representing the different layers of the application. The Data Access Layer (DAL) has a model of the database in it and more importantly --for my issue-- a Plain Old Class Object (POCO). I want to send an instance of this POCO to an external requester via a WCF contract. As you know, I must define the Operations Contract and Data Contract at the contract layer. It is here were my problem lies, how do I declare the data contract and its data members when the POCO is situated in another layer?

I have tried defining an interface and have both classes implement it, but I come up against a problem when I am getting the objects from the database and then passing them through the contract, the contract does not know the object being passed to it - even though it shares an interface.

Anyway, hope that is clear (as mud!), and if anyone can advise me on a suitable solution I would be much obliged.

P.S. Using C# in VS2015

Upvotes: 0

Views: 67

Answers (1)

Rian Mostert
Rian Mostert

Reputation: 714

Looks to me like what you need is another class specifically built for the WCF layer that contains all the properties and attributes you need to use and then use something like AutoMapper to copy to contents across to your WCF object.

Making use of the Factory Design Pattern could also be of helper here.

Upvotes: 1

Related Questions