微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐