ASP.NET MVC 中的业务逻辑层

Business Logic Layer in ASP.NET MVC

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

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

是的,你可以。

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

的好方法

举个例子: 你有一个 BLL class

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);
    }
   }

希望对您有所帮助。