I have a layer of business-level objects and a layer of contract-level objects in a WCF service application. The business-level objects that I refer to are entity objects or POCOs that I use to store data. The contract-level objects that I mean for are the objects that make up the WSDL that my clients see (also POCOs).
When I return data from my WCF service to the client, the request parameters are hydrated from one or more objects of my contract level in XML and redirected.
I am trying to create a class that is outside the contract and business layer, which will transfer objects from one layer to another. So, for example, in the contract layer, I will have a class like:
public class Person
{
public string Name { get; set;};
}
I could also have an identical class (or it could be different) in a business layer whose property would be mapped to the property of this class.
Then I have a class that executes code that looks like this:
public Contract.Person TranslatePerson(Business.Person person)
{
Contract.Person result = new Contract.Person();
result.Name = person.Name;
return result;
}
Everything works as expected. However, one of the requirements of this translation service is to isolate the business level from changes at the contract level, and one of the requirements of this level is the simultaneous existence of different versions of the contract level to support backward compatibility for SOAP clients, For example, if in v2 services I want to add a last name in class person and change Name to FirstName so that my SOAP clients can now see both data points, I will have something like this:
namespace Contract.V1
{
public class Person
{
public string Name { get; set;};
}
}
namespace Contract.V2
{
public class Person
{
public string FirstName { get; set;};
public string LastName { get; set;};
}
}
, V2 Person , FirstName FirstName - LastName LastName. , V1, FirstName Name LastName.
, , :
public class V1Translator
{
public virtual Contract.V1.Person TranslatePerson(Business.Person person)
{
Contract.V1.Person result = new Contract.V1.Person();
result.Name = person.Name;
return result;
}
}
public class V2Translator : V1Translator
{
public override Contract.V2.Person TranslatePerson(Business.Person person)
{
Contract.V2.Person result = new Contract.V2.Person();
result.Name = person.Name;
return result;
}
}
, 100 V1Translator, 2 3 V2Translator, . Translator factory. , TranslatePerson TranslationService , . , , , . , . , Contract Person, . .
- ?