我想学习如何正确地构建分层架构。为此我需要一个建议。
例如,我开始写新闻网站。我将我的项目分层:
这样做最好吗?我会做那个角度的(在网络项目中)。
再来一个。我应该再为依赖注入做一个图层吗?
发布于 2017-01-06 15:14:42
我不认为它是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大小写命名约定。这样,我就不必处理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
{
}
}
这样,它们共享相同的名称空间,我可以很容易地将它们关联起来。
发布于 2017-01-06 15:01:11
我经常使用那种建筑结构。在相同的情况下,意味着webAPI和角。
但是,重要的是要考虑到项目中的所有需求,包括项目的维度。例:如果你真的不需要管理业务逻辑,那么使用BLL可能就没有意义了。
https://stackoverflow.com/questions/41508099
复制相似问题