加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 10:01:34 所属栏目:asp.Net 来源:网络整理
导读:我有一个ASP.NET Web应用程序,它有一个UI项目和BL项目. BL项目处理所有业务逻辑和数据访问部分.我通过简单地调用实例上的方法从我的UI调用BL方法. Public Class User Public Property UserID As Integer Public Property FirstName As String //rest of the
我有一个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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读