我们已经成功地完成了新的web应用程序的开发。它有表示层、业务层和数据访问层。
对于新的web应用程序,我们移植了现有的业务层&数据访问层,只有表示层将被更改。
虽然我们将使用相同的业务层,但在某些情况下,可以有不同的模型,而不是现有的模型。
我们计划建立中间层(新模型)和转换功能,从现有业务层交付的模型生成新模型。
namespace Busniess
{
public class Employee
{
public string FirstName {get; set;}
public string LastName {get; set;}
}
}新的中间层,
namespace Intermediate
{
public class Employee
{
public string Address {get; set;}
public string Zip {get; set;}
}
}当我创建employee实例时,Employee对象应该能够转换成以下场景
1. GetAll (all the properties FirstName, LastName, Address & Zip)
2. Selected (FirstName & Address) - if possible controlled through attribute decoration.创建中间层转换功能的最佳方法是什么?
如果中间层和转换函数不是很好的候选函数,那么最好的方法是什么?
发布于 2016-11-19 10:17:20
根据您的理解,您的中间层稍后只是对实际业务层的调用,具有额外的扩展/属性。其中一种方法是从业务对象继承到中间层。这样,您就可以将业务层的所有功能访问到中间层,并且代码将符合干的原则。
namespace Intermediate
{
public class Employee : Busniess.Employee
{
public Employee() : base() { }
public string Address { get; set; }
public string Zip { get; set; }
}
}https://stackoverflow.com/questions/40687429
复制相似问题