中间层和转换功能的最佳方法

Best approach for the intermediate layer & Conversion function

我们已成功开发新的网络应用程序。它有表示层、业务层和数据访问层。

对于新的 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.

创建中间层和转换函数的最佳方式是什么?

如果中间层和转换功能不是一个好的选择,最好的方法是什么?

根据您的理解,您稍后的中间层只是通过额外 extensions/attributes 调用实际业务层。其中一种方法是从 Business 对象继承到中间层。通过这种方式,您将可以访问业务层的所有功能到中间层,并且代码将符合 DRY 原则。

namespace Intermediate
{
    public class Employee : Busniess.Employee
    {
        public Employee() : base() { }
        public string Address { get; set; }
        public string Zip { get; set; }
    }
}