问题标签 [n-layer]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
699 浏览

c# - Do I need Entity Framework Referenced In My UI even if access is limited to my data access layer?

I have an n-layered application with data base activity performed in my data access layer. I have an application layer which asks my data access layer to perform tasks from the repositories in the data access layer. My user interface, which for now is a simple console app to test results, asks my application layer to get things like a list of data which in turn the application layer gets from the repository and it all gets back to the console app.

If I don't add the entity framework as a reference in my console app, I get the following error:

The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Why am I getting this error when the console app makes no data access calls or entity framework operations? All that is done in my data access layer which does have Entity Framework referenced.

Update: Below is my console interface:

Below is the App.config.

If I just remove the entityFramework sections and database strings I get the following error:

{"Schema specified is not valid. Errors: \r\nModelEntities.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."}

Then if I remove the configuration section which does an entityframework registstration I get the same error.

All these errors go away if I add EntityFramework to the consoled project of my solution which also adds these entries into the app.config

0 投票
4 回答
714 浏览

entity-framework - 如何在 N 层架构中模拟实体框架

我有一个带有实体框架(代码优先方法)的 N 层应用程序。现在我想自动化一些测试。我正在使用Moq 框架。我在编写测试时发现了一些问题。也许我的架构是错误的?错了,我的意思是我编写的组件没有很好地隔离,因此它们不可测试。我不太喜欢这个……或者,我根本无法正确使用 moq 框架。

我让你看看我的架构:

在此处输入图像描述

在每个级别,我都将我的注入context到类的构造函数中。

门面:

BLL:

存储库:

IDataContext是由我的 DbContext 实现的接口:

现在,我如何模拟EF以及如何编写测试:

在哪里ContextHelper.CreateCompleteContext()

在这里我如何编写我的测试:

这里似乎一切正常!!!看起来我的架构是正确的。但是如果我想插入/更新一个实体呢?没有任何工作了!我解释为什么:

如您所见,我将一个*Request对象(它是 DTO)传递给外观,然后在我的 TOA 中,我从 DTO 的属性生成我的实体:

PaymentAttemptTrace是我将插入到实体框架的实体。它没有被模拟,我无法注入它。因此,即使我通过了我的模拟上下文(IDataContext),当我尝试插入一个未模拟的实体时,我的测试也会失败!

这里有人怀疑我有一个错误的架构!

那么,怎么了?我使用最小起订量的架构或方式?

谢谢你的帮助

更新

这里我如何测试我的代码..例如,我想测试支付的痕迹..

这里是测试:

这里的门面:

这是我如何开发的PaymentsManager

最后我是如何编写存储库的:

0 投票
1 回答
383 浏览

c# - C# NAudio 在没有 DMO 或 ACM 的情况下渲染波形 ASP.net

我试图在 Azure 网站(没有安装 ACM 或 DMO 编解码器)上使用 ASP.net 绘制波形,所以我不得不使用 NLayer 来读取 mp3 文件。我下面的代码与常规的 DmoMp3FrameDecompressor 完美配合,但是当我使用 NLayer 解压缩器时,它就不行了。

也许 NLayer 解压器的格式是 32bit Float 而不是 16bit PCM。

0 投票
2 回答
214 浏览

c#-4.0 - N 层和 N 层或层和层架构相同?

谁能告诉我 N 层和 N 层架构有什么区别。我知道 3 层架构有 ​​3 层:UI、业务逻辑层(BLL)和数据逻辑层(Dll)

但是现在,我的问题是什么是 N-Tier 和 N-Layer,它们之间有什么区别。

此外,就 C# 而言,这些如何与一层到另一层交互?

0 投票
2 回答
8386 浏览

architecture - Monolith 和 n 层有什么区别?

我有几个关于单体n 层架构的问题。

首先,Monolith 和 n 层架构有什么区别?

其次,假设我有一个包含多个项目的 Visual Studio 解决方案,例如:

  1. 表示层
  2. 服务层
  3. 业务层
  4. 跨层
  5. 数据层
  6. 单元测试

这被认为是单体架构还是 n 层架构?

如果我有包含(比如说)3 个 Web API 的微服务,并且我在单个单独的 Visual Studio 解决方案中构建每个服务,是否可以实现我以前的项目结构(服务层、业务层、数据层等)?

非常感谢你,对不起我的英语不好。

0 投票
2 回答
80 浏览

c# - 插入后 C# n 层实体更改未反映在 DTO 中

抱歉标题,我找不到合适的描述。

我有四层:

  • 核心层:包含 DTO、服务和存储库的接口。
  • 业务层:包含处理业务逻辑的“服务”。
  • 数据访问层:包含处理数据库访问和实体到 DTO 的转换的存储库。
  • 表示层:UI 的东西

我遇到了一个我不知道如何最好地解决的问题。我正在向数据库异步添加一个实体,如下所示:

管理费率服务:

管理率存储库:

存储库:

这确实有效,问题是在添加之后,新生成的实体 id 没有反映在 DTO (DTO.ID = 0) 中。

我不可能返回更新后的实体,因为它需要我将实体转换为我的表示层中的 DTO,以使其始终保持异步。

由于通用存储库,我也不能只返回 ID。

我真的不想摆脱通用存储库,因为它非常有用,但是我真的看不到另一种在不更改数据库的情况下安全地执行此操作的方法(我不能这样做)。

那么,我该怎么办?

0 投票
1 回答
488 浏览

architecture - 从 N 层转换为 DDD

我正在努力理解如何通过让我的域实体有自己的行为来将我的网站重构为更简洁的代码。

我希望我已经设法在这张图中描述了我的问题:

在此处输入图像描述

A是我当前设计的 Web 应用程序项目,而B是我的目标设计。

我正在尝试将我当前 BL 中的所有逻辑插入到我的实体中,以便如下代码行:

var customer = new CustomerLogic().GetCustomer(id);

将变为:

var customer = new Customer(id);

或者,

var customer = Customer.Get(id);

当我看到多态情况时,这一点就更加明显了。

问题是,虽然在我当前的设计中(A)实体只是被使用,所以所有项目都有对它的引用,而未来的设计(B)实体将必须对较低层有引用。

但是由于我还希望我的 DAL 将我的实体交付回调用客户端,所以我得到了一个循环引用。

我目前的设计使我的代码比面向对象更程序化,我想改变它。

那么,如何在维护 DDD 的同时解决此循环引用?

0 投票
0 回答
24 浏览

.net - 项目可以引用其他项目中未在 .NET Core/.NET Standard 中直接引用的类

我正在设计一个 N 层应用程序。该解决方案有 5 个项目:A、B、C、D 和 E。

项目之间的引用是这样的:

A -> B, E

B -> C, E

C -> D, E

D -> E

即使我没有从 A 到 D 的显式引用,我也可以通过导入命名空间来毫无问题地访问它。在扩展 A 的项目引用时,我看到 B 被引用。如果我展开 A>B,那么我会看到 C 等等。

这是设计使然吗?

0 投票
2 回答
545 浏览

c# - 如何将用于审计目的的 Web n 层应用程序中的用户身份从用户界面层传递到数据访问层?

我已经构建了一个以 n 层架构构建的 Web 应用程序,即 UI、BLL、API (WebAPI)、DAL。我希望通过这种关注点分离来实现对 DAL 的基本审核,即 RowCreatedBy、RowUpdatedBy 等,但是我想找出将用户身份从 UI 层向下传递到我的数据访问层,而不将其作为参数添加到我所有的 crud 调用中。那里的选项是使用 Thread.CurrentPrincipal,但是它可以工作,但问题是我的应用程序托管在具有特定标识集的应用程序池下的 IIS 中。我希望 CurrentUser 在我的所有应用程序层中都可用。请告知最好的方法?

注意:我知道人们可能会问过这个问题,但从我看到的其他参考资料来看,没有一个能满足我的情况。

0 投票
2 回答
219 浏览

c# - 应用程序的 n 层架构中可以有哪些额外的层?

我研究软件架构原理。
我明白什么是三层架构(包含演示-业务-数据访问)。
但是任何人都有任何想法或额外的层来做到这一点,例如有人通过额外的层来做到这一点,例如“服务”层“基础设施”层或其他层等。
有没有额外的层来做呢?
我对这样做感到困惑。
请帮我 ...