一个程序集中的分层架构 [英] Layered Architecture Inside One Assembly

查看:26
本文介绍了一个程序集中的分层架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更喜欢将我的 3 层 .NET 应用程序分成单独的项目以增强模块化和关注点分离,但我的计算机存在性能问题(没有足够的内存和处理能力),因此 Visual Studio 运行缓慢且工作不愉快当一个解决方案中有许多项目时,所以我虽然将所有层放在一个程序集中,但仍然使用代码并将其设计为好像每种类型都在其各自的层中.我想知道一件事,如果你们中有人尝试过这样做,您有什么建议或不建议这样做或对此有任何想法吗?
我不是在寻找讨论,我只是想知道这样做是否有任何严重的风险?

I Prefer to separate my 3 layer .NET applications into separate projects to enhance modularity and separation of concerns, but i have performance issues on my computer (not enough memory and processing power) so visual studio is slow and not pleasing to work with when there is many projects in one solution, so i though of putting all the layers in one assembly but still use the code and design it as if each type is in its respective layer. I want to know one thing, if any of you have tried doing this, is there anything you recommend or don't or any idea regarding this ?
I am not looking for a discussion, i just want to know if there is any serious risks doing it this way ?

推荐答案

分层在 .NET 和其他强类型平台中有益的原因之一是您不能(轻松)在项目/库之间添加循环引用.这确保,至少在包级别,依赖项将形成有向无环图 (DAG).这是一件好事,因为它迫使我们减少耦合.

One of the reasons that layering is beneficial in .NET and other strongly-typed platforms is that you can't (easily) add circular references between projects/libraries. This ensures that, at least at the package level, dependencies will form a Directed Acyclic Graph (DAG). This is a good thing, because it forces us to reduce coupling.

C#中,完全可以编译形成循环图的代码(ClassA引用ClassB,它引用ClassCcode>,它反过来引用 ClassA).因此,将所有代码放入单个 Visual Studio C# 项目会消除分层提供的一些编译时保护.

In C#, it's perfectly possible to compile code that forms Cyclic Graphs (ClassA references ClassB, which references ClassC, which in turn references ClassA). Thus, putting all code into a single Visual Studio C# project removes some of the compile-time protection that layering provides.

但是,如果您改为使用 F# 编写整个项目,您将重新获得编译时保护,因为 F# 代码如果包含循环则不会编译(尽管可以声明特定异常该规则模块中...请参阅相互递归类型).

However, if instead you write the entire project in F#, you'll regain that compile-time protection, because F# code doesn't compile if it contains cycles (although one can declare specific exceptions to that rule within a module... see the section on Mutually Recursive Types).

因此,如果使用 C# 编写整个应用程序,您很可能会遇到问题,但是如果您使用 F# 编写它,则应该会很好.

So, if write the entire application in C#, you're most likely going to have problems, but if you write it in F#, you should be good.

这篇关于一个程序集中的分层架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆