分层架构。做得对

时间:2017-01-06 14:46:45

标签: c# asp.net architecture

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

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

enter image description here

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

还有一个。我应该再为依赖注入创建一层吗?

2 个答案:

答案 0 :(得分:3)

我不会将其称为BLL,因为听起来// 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 只能用于网络应用程序。

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

Contoso.Business.Tests

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

此外,我的Contoso.Buiness将驻留在与Contoso.Business命名空间匹配的命名空间中。这是public namespace Contoso.Business { public class Foo { } } 中的一个课程:

Contoso.Business.Tests

该类的测试,我不会把它放入Foo命名空间(我不是在谈论DLL)。我会让我的测试类正在测试// 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 { } } ,如下所示:

builds_dir

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

答案 1 :(得分:1)

我经常使用那种建筑结构。在相同的情况下,意思是webAPI和angular。

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

相关问题