简体   繁体   English

我可以在我的 ApplicationLogic 项目(net standard 2.1)中的 MVC(.net core 3.0)项目中使用视图模型吗?

[英]Can I use viewmodels in my MVC(.net core 3.0) project in my ApplicationLogic project (net standard 2.1)

I have an MVC app where all my view models are in. I added a Business Logic layer project, which is a class library project net standard 2.1, where all my interfaces and services are.我有一个 MVC 应用程序,我的所有视图模型都在其中。我添加了一个业务逻辑层项目,这是一个 class 库项目网络标准 2.1,我的所有接口和服务都在其中。 I am trying to use my viewmodels in the business logic project, but I can not reference them there.我正在尝试在业务逻辑项目中使用我的视图模型,但我无法在那里引用它们。 I wanted to know can I reference an MVC app in a class library, if not where can I put my view models if I don't want to add DTOs because my app is not a very big project.我想知道是否可以在 class 库中引用 MVC 应用程序,如果我不想添加 DTO,我可以将我的视图模型放在哪里,因为我的应用程序不是一个很大的项目。

There's a lot of confusion here.这里有很多混乱。 First, there's nothing magical about a view model or DTO, and the names are merely descriptive of a particular context of usage.首先,视图 model 或 DTO 并没有什么神奇之处,其名称只是对特定使用上下文的描述。 At the end of the day, you have a class that represents some collection of data in a particular context: that is all.归根结底,您有一个 class 代表特定上下文中的一些数据集合:仅此而已。 Second, business logic is not application logic.其次,业务逻辑不是应用程序逻辑。 Application logic is about presentation and user interaction, whereas business logic is about raw data.应用程序逻辑是关于表示和用户交互的,而业务逻辑是关于原始数据的。 Those two things should not cross because business rules should not determine presentation and presentation should not determine business rules.这两件事不应该交叉,因为业务规则不应该决定展示,展示也不应该决定业务规则。

The business layer should not know anything about your view models in your application layer (the MVC app), as that would create a tight coupling (and a circular reference, FWIW).业务层不应该对应用层(MVC 应用程序)中的视图模型一无所知,因为这会产生紧密耦合(以及循环引用,FWIW)。 The logic for mapping to/from the view models in the application layer to the entities in the business layer is the domain of the application layer alone.将应用层中的视图模型映射到/从应用层中的实体映射到业务层中的实体的逻辑仅是应用层的领域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 面向 .NET Standard 时,我到底可以在我的项目中使用 .NET Core 和 .NET Framework 中的哪些内容? - When targeting .NET Standard, what exactly can I use from .NET Core and .NET Framework in my project? 如何在ASP.NET MVC 5.1项目中通过控制器的动作使用标准JSON格式器? - How can I use the standard JSON formatter from an action of my controller in an ASP.NET MVC 5.1 project? 问题:在.Net Core 3.1 中引用.Net Standard 2.1 项目 - Issue: Referring .Net Standard 2.1 project in .Net Core 3.1 将 Web 应用项目添加到我的解决方案中,并且解决方案中的其他项目已经使用 .net 框架,我可以将 .net 核心用于新项目吗? - adding a web app project to my solution, and the other projects in the solution already use .net framework, can I use .net core for the new project? Porting.Net Core (2.2) web app to .Net 标准 (2.1) 用于 Xamarin 项目 - Porting .Net Core (2.2) web app to .Net standard (2.1) for use in Xamarin project 我将我的 .NET CORE 项目从 2.1 更新到 3.1,但我在类 Startup 中有一些错误 - I updated my .NET CORE project from 2.1 to 3.1, yet I have some errors in the class Startup 尝试运行 my.Net Core MVC 项目时出错。 我能做些什么? - Error trying to run my .Net Core MVC Project. What can I do? 我可以在 127.0.0.1 而不是本地主机上运行我的 asp.net 核心 mvc web 项目吗 - Can i run my asp.net core mvc web project on 127.0.0.1 instead of local host 如何在我的 New.Net Core 项目中修复 DbUpdateConcurrencyException? - How Can I Fix DbUpdateConcurrencyException In My New .Net Core Project? 如何在 ASP.NET MVC Core 中使用来自另一个项目的 ViewModel - How to use ViewModels from another project in ASP.NET MVC Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM