asp.net – 如何在我的代码中使用接口使其更加scalabale?

我有一个ASP.NET Web应用程序,它有一个UI项目和BL项目. BL项目处理所有业务逻辑和数据访问部分.我通过简单地调用实例上的方法从我的UI调用BL方法.

Public Class User

    Public Property UserID As Integer
    Public Property FirstName As String
    //rest of the properties for user


  Public Sub Save()
   //save the details to the database
  End sub
End Class

从我的UI(它在C#中)我这样做.

User objUser=new User();
  objUser.FirstName="Happy";
  objUser.Save();

一切正常.由于项目正在增长,我考虑尝试添加某种单元测试/依赖注入测试.用Google搜索并看到每个示例都使用Interfaces.我读了很多关于接口但不知道如何在我的编码中包含接口并使其遵循更好(可扩展和可测试)的模式.除了可测试性,它会给我一些其他优势吗?

有人可以给我一个示例如何做到这一点?

解决方法

看一下 Model-View-Controller设计模式和 asp.net mvc framework. here一个很好的概述,解释了这种设计策略的好处.

摘录在这里

The MVC pattern helps you create applications that separate the
different aspects of the application (input logic,business logic,and
UI logic),while providing a loose coupling between these elements.
The pattern specifies where each kind of logic should be located in
the application. The UI logic belongs in the view. Input logic belongs
in the controller. Business logic belongs in the model. This
separation helps you manage complexity when you build an application,
because it enables you to focus on one aspect of the implementation at
a time. For example,you can focus on the view without depending on
the business logic.

The loose coupling between the three main components of an MVC application also promotes parallel development. For example,one developer can work on the view,a second developer can work on the controller logic,and a third developer can focus on the business logic in the model.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....