【问题标题】:Business Logic Layer in ASP.NET MVCASP.NET MVC 中的业务逻辑层
【发布时间】:2015-07-01 10:19:10
【问题描述】:

我正在努力寻找一些关于我应该将业务逻辑放在哪里的信息。我有一个想要移动到 ASP.NET MVC 4 应用程序中的 N 层 Win Forms 应用程序。

我可以重复使用现有的 BLL 和 DAL 对象吗?如果是这样,我是将它们连接到模型还是控制器?

【问题讨论】:

  • 您现有的 Windows 应用程序的结构是什么?您的结构中是否有实体或领域项目?
  • 您能否提供一些有关您当前应用程序的高级信息?
  • 是的,UI 是连接到 BLL(独立类库)的 Winform,而 BLL(独立类库)又使用 DAL(独立类库)读取和写入 SQL Server 后端。

标签: asp.net-mvc-4 architecture


【解决方案1】:

是的,你可以。

您的控制器将访问您的顶层(BLL 或 DAL,具体取决于您的拓扑)。只要你的 BLL/DAL 有接口,这将是重构和测试你的类的好方法

【讨论】:

【解决方案2】:

例如: 你有一个 BLL 课程

public class StudentDLL: IStudentDLL
{

 public List<student> GetAll()
  {
   //you can add your BLL here or the DLL be referenced in your BLL
    return List<student>(){ new student()
    {
      studentid=1,studentname="David"
       },
     new student(){
     studentid=2,studentname="Andrew"
     },new student(){
     studentid=3,studentname="Mark"
     }}
  }}

在您的控制器上,您将拥有

 public class StudentController: Controller
  {
   public IStudentDLL _student;

  public StudentController(IStudentDLL student){
  _student = student;
  }
    public ActionResult Index()
    {
     var studentList= _student.GetAll();
    var model= studentList;

    return View Index("Index", model);
    }
   }

希望这会有所帮助。

【讨论】:

  • 谢谢,有道理。
猜你喜欢
  • 2017-01-10
  • 2011-12-03
  • 2011-09-03
  • 2021-02-24
  • 2018-04-17
  • 2014-07-15
  • 2010-12-18
  • 1970-01-01
  • 2013-05-24
相关资源
最近更新 更多