首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >分层架构。做得对

分层架构。做得对
EN

Stack Overflow用户
提问于 2017-01-06 14:46:44
回答 2查看 106关注 0票数 2

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

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

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

再来一个。我应该再为依赖注入做一个图层吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-01-06 15:14:42

我不认为它是NewsWebSite.BLL,因为它听起来像是BLL只能用于web应用程序。

我会这样做的。如果公司名称为Contoso:

代码语言:javascript
运行
复制
// 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大小写命名约定。这样,我就不必处理Contoso.BLL.SomeClass了。

而且,我的Contoso.Business.Tests将驻留在一个与我的Contoso.Buiness命名空间相匹配的名称空间中。下面是Contoso.Business中的一个类

代码语言:javascript
运行
复制
public namespace Contoso.Business
{
    public class Foo 
    {

    }   
}

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

代码语言:javascript
运行
复制
// 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 
    {

    }   
}

这样,它们共享相同的名称空间,我可以很容易地将它们关联起来。

票数 3
EN

Stack Overflow用户

发布于 2017-01-06 15:01:11

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41508099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档