【问题标题】:layered architecture. do it correctly [closed]分层架构。正确地做[关闭]
【发布时间】:2017-05-21 08:35:13
【问题描述】:

我想学习如何正确地制作分层架构。为此,我需要一个建议。

例如我开始写新闻网站的项目。我分层了我的项目:

这样做最好吗?我会做那个角度的(在网络项目中)。

还有一个。我应该为依赖注入多做一层吗?

【问题讨论】:

  • 这是一个好方法——“最好”是主观的。试试这种方式,看看你遇到了什么问题。
  • @DStanley 感谢您的建议
  • 你应该在每一层都有单元测试。 NewsWebsite.BLL.Tests、NewsWebsite.Data.Tests...以及一个单独的集成测试项目,用于测试整个系统。
  • @Fran 为每一层单独层?有趣
  • @GiorgiPilishvili 解决方案中的每个项目都应该有一个对应的 .Tests 项目用于单元测试。

标签: c# asp.net architecture


【解决方案1】:

我经常使用这种建筑结构。在相同的情况下,意味着 webAPI 和 angular。

但重要的是您要考虑项目中的所有需求,包括它的维度。例如:如果您真的不需要管理业务逻辑,那么使用 BLL 可能就无关紧要了。

【讨论】:

    【解决方案2】:

    我不会称它为NewsWebSite.BLL,因为听起来BLL 只能用于Web 应用程序。

    我会这样。如果公司名称是 Contoso:

    // This is where you can put all your common code. 
    // I do not mean cross cutting concern here. By common I mean if you have 
    // some contstants or enums that are shared by all Dlls
    Contoso  
    
    Contoso.Business
    Contoso.Api
    Contoso.WebApp
    Contoso.Data
    
    // The name of test projects are exactly the same as the name of the 
    // assembly but has the word "Tests" at the end
    Contoso.Business.Tests 
    Contoso.Api.Tests
    

    此外,请参阅我正在使用的 Pascal Casing 命名约定。这样我就不必处理 Contoso.BLL.SomeClass。

    另外,我的Contoso.Business.Tests 将驻留在与我的Contoso.Buiness 命名空间匹配的命名空间中。这是Contoso.Business中的一个类:

    public namespace Contoso.Business
    {
        public class Foo 
        {
    
        }   
    }
    

    该类的测试,我不会将它放入Contoso.Business.Tests 命名空间(我不是在谈论DLL)。我会让我的测试类像这样测试Foo

    // See the namespace here, I am not using Contoso.Business.Tests
    public namespace Contoso.Business
    {
        // The name of the class is identical to the name of the class being tested but the word "Tests" appended
        public class FooTests 
        {
    
        }   
    }
    

    这样它们共享相同的命名空间,我可以轻松地将它们关联起来。

    【讨论】:

    • 不错的建议。谢谢
    • 别担心,伙计。如果这回答了您的问题,请阅读this
    猜你喜欢
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 2015-04-04
    • 2012-11-30
    • 2010-11-14
    • 1970-01-01
    相关资源
    最近更新 更多